欢迎来到天天文库
浏览记录
ID:38025160
大小:32.00 KB
页数:3页
时间:2019-05-24
《VisualC++6.0中《约瑟夫序列》程序注解》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、#include#include#definelensizeof(structnode)#defineA100#defineB200#defineM20/*初始值*/structnode{intnumber;intcode;structnode*next;};structnode*insert(structnode*tail,intnumber,intcode)/*假设tail就是表尾,返回指向末尾的指针*/{structnode*p0;p0=(struct
2、node*)malloc(len);p0->number=number;p0->code=code;p0->next=NULL;tail->next=p0;returnp0;}structnode*del(structnode*head,int*a)/*删除从tail数起第a个结点,返回下一个结点地址*/{intcount=1;intt;structnode*p0;if(*a==1){t=head->number;while(head->next->number!=t){head=head->n
3、ext;}p0=head->next;head->next=p0->next;*a=p0->code;printf("%d",p0->number);free(p0);}else{while(count!=(*a-1)){head=head->next;count++;}p0=head->next;head->next=p0->next;*a=p0->code;printf("%d",p0->number);free(p0);}returnhead->next;}voidprint(st
4、ructnode*head){structnode*p0=head;while(p0->next!=head){printf("%d%d",p0->number,p0->code);p0=p0->next;}printf("%d%d",p0->number,p0->code);printf("");}voidmain()/*链表使用头结点*/{structnode*tail,*head;intnumber=1;intcode=1;intm=M;intcount=0;/*记录输入人数*
5、/head=tail=(structnode*)malloc(len);tail->code=A;tail->number=B;tail->next=NULL;printf("输入序号以及对应号码,序号为0时结束。");scanf("%d%d",&number,&code);while(number){count++;tail=insert(tail,number,code);scanf("%d%d",&number,&code);}tail->next=head->next;head=he
6、ad->next;printf("序号与密码对应如下:");print(head);while(head->next!=head){m=m%count;head=del(head,&m);count--;}printf("%d",head->number);}
此文档下载收益归作者所有