![]() |
#2
rjsp2021-01-12 09:25
|

#include<stdio.h>
#include<stdlib.h>
typedef struct ptr//链表结构
{
int a;
struct ptr *next;
}ptr;
int main ()
{
int n,i;
ptr head;
ptr *t=&head;
scanf("%d",&n);
for(i=0;i<n;i++)//初始化链表作编号,依次1,2,3,4...
{
ptr *circle_node=(ptr*)malloc(sizeof(ptr));
t->next=circle_node;
t=circle_node;
t->a=i+1;
}
ptr *node=&head;//把尾节点连接到头结点
ptr *front;
t->next=node->next;
free(node);
while(t->next!=0)//链表长度大于一个元素时
{
for(i=0;i<3;i++)//报数三次
{
front=t;
t=t->next;
}
node=t;
front->next=t->next;
t=front;
free(node);
}
printf("%d",t->a);
return 0;
}
#include<stdlib.h>
typedef struct ptr//链表结构
{
int a;
struct ptr *next;
}ptr;
int main ()
{
int n,i;
ptr head;
ptr *t=&head;
scanf("%d",&n);
for(i=0;i<n;i++)//初始化链表作编号,依次1,2,3,4...
{
ptr *circle_node=(ptr*)malloc(sizeof(ptr));
t->next=circle_node;
t=circle_node;
t->a=i+1;
}
ptr *node=&head;//把尾节点连接到头结点
ptr *front;
t->next=node->next;
free(node);
while(t->next!=0)//链表长度大于一个元素时
{
for(i=0;i<3;i++)//报数三次
{
front=t;
t=t->next;
}
node=t;
front->next=t->next;
t=front;
free(node);
}
printf("%d",t->a);
return 0;
}