#include typedef struct student {
int number;
struct student *next;
}*node, Node; /* 定义结点*/
node creat(int n); //创建链表函数
void function(node l1, int baoshu); //声明运行函数
int i;
int main()
{
int n; //人数
node head1; //链表的头结点
int baoshu = 3;
scanf("%d",&n);
head1 = creat(n);
function(head1,baoshu);
return 0;
}
node creat( int n)
{
node h; //头结点指针
h = (node)malloc(sizeof(Node)); //创建头结点
h->next = NULL; //头结点的next赋为空
node q = h; //q指向头结点
node p; //定义指针p
for(i=1;i<=n;i++) //创建n个结点
{
p = (node)malloc(sizeof(Node));
(*p).number = i; //输入结点编号
p->next = q->next; //采用尾插法插入结点
q->next = p;
q = p;
}
q->next = h->next; //尾结点和首节点连接
return(h); //返回头结点
}
void function(node l1, int baoshu) //移除结点
{
node p = l1->next; //指向首节点
free(l1); //移除头结点
node q = NULL; // 指向被移除的结点,释放移除的结点
while(p->next!=p)
{
for( i=1;i<=baoshu-2;i++)//??移动到离开的人的结点的前一个,只需要移动baoshu-2
{
p = p->next;
q = p->next; //记录删除的人的结点
p->next = q->next; //把q结点从链表移除
p = p->next; //移动到下一个开始报数的人,很重要的一步
free(q); //释放q结点
}
}
printf("%d",p->number);
free(p); //把最后一个结点free
}
```