【c语言】数据结构(约瑟夫生者死者游戏的问题)
1#include
2#include 3struct DuLNOde{
4 5int date;
6structDuLNOde * next;
7};
8int main()
9{
10structDuLNOde *q=NULL;
11structDuLNOde *p=NULL;
12structDuLNOde *z=NULL;
13q=(structDuLNOde*)malloc(sizeof(struct DuLNOde));
14if(!q)
15exit(0);
16p=q;
17p->date=1;
18p->next=p;
19for(inti=2;i<=30;i++)
20 {
21z=(structDuLNOde*)malloc(sizeof(struct DuLNOde));
22if(!z)
23exit(0);
24z->date=i;
25z->next=p->next;
26p->next=z;
27p=p->next;
28 }
29p=q;
30for(inti=0;i<15;i++)
31 {
32for(intj=1;j<8;j++)
33p=p->next;
34printf("%d\n",p->next->date);
35p->next=p->next->next;
36p=p->next;
3738 }
39}
来源: http://www.bubuko.com/infodetail-2002379.html