不知道符不符合题意
#include
#include
struct student
{
int num;
struct student* next;
};
#define LEN sizeof(struct student)
struct student* create(int n)
{
int i;
struct student* p1, *p2, *head;
p2 = p1 = (struct student*)malloc(LEN);
p1->num = 1;
head = p1;
p1->next = NULL;
if (n > 1)
{
for (i = 2; i <= n; i++)
{
p1 = (struct student*)malloc(LEN);
p1->num = i;
p2->next = p1;
p2 = p1;
}
p1->next = NULL;
}
return head;
}
int main()
{
int i;
struct student* head, *p, *p2;
head = create(30); //n=30
p = head;
//将链表置环
do
{
//printf("%d ", p->num);
p = p->next;
}
while (p->next != NULL);
p->next = head;
//开始剔除
p2 = p = head;
for (i = 1; p->next != p; i++)
{
if (i % 21 == 0) //k=21
{
p2->next = p->next;
p = p->next;
}
else
{
p2 = p;
p = p->next;
}
}
printf("\n%d\n", p->num);
return 0;
}