C程序设计(第五版)【谭浩强】第九章课后习题6
#include<stdio.h>
int main()
{
struct node
{
int data;
struct node *next;
};
struct node peo[13], * head;
head = peo;
for (int i = 0; i < 13; i++)
{
head->data = i + 1;
head->next = &peo[i + 1];
head = head->next;
}
peo[12].next = peo;
head = peo;
int i = 1;
int count = 13;
while (count > 1)
{
if (i == 0)
{
head = head->next;
continue;
}
if (i == 3)
{
printf("此时淘汰的人是:%d\n", head->data);
head->data = 0;
count--;
}
head = head->next;
i++;
if (i > 3)
{
i = 1;
}
}
printf("-------------------------------\n");
while (head->data == 0)
{
head = head->next;
if (head->data != 0)
{
printf("留到最后的是 %d \n", head->data);
}
}
return 0;
}