Josephus问题C语言单循环链表.doc

上传人:PIYPING 文档编号:10602480 上传时间:2021-05-25 格式:DOC 页数:4 大小:32KB
返回 下载 相关 举报
Josephus问题C语言单循环链表.doc_第1页
第1页 / 共4页
Josephus问题C语言单循环链表.doc_第2页
第2页 / 共4页
Josephus问题C语言单循环链表.doc_第3页
第3页 / 共4页
Josephus问题C语言单循环链表.doc_第4页
第4页 / 共4页
亲,该文档总共4页,全部预览完了,如果喜欢就下载吧!
资源描述

《Josephus问题C语言单循环链表.doc》由会员分享,可在线阅读,更多相关《Josephus问题C语言单循环链表.doc(4页珍藏版)》请在三一文库上搜索。

1、#include#include#includestruct node;struct list;typedef struct node * pnode;typedef struct list * plist;struct nodechar info;pnode next;struct listpnode head,tail;pnode creat_node(char info1)pnode p=(pnode)malloc(sizeof(struct node);if(p)p-info=info1;p-next=0;return p;elsereturn 0;plist creat_list()

2、plist lst=(plist)malloc(sizeof(struct list);if(lst)lst-head=lst-tail=0;return lst;elsereturn 0;int isempty(plist lst)return lst-head=0;void add_to_tail(plist lst,char info1)pnode p=creat_node(info1);if(p)if(isempty(lst)lst-head=lst-tail=p;else lst-tail-next=p;p-next=lst-head;lst-tail=p;elseprintf(fa

3、il to creat new memory spacen );void fun(plist lst,int n1,int n2)if(isempty(lst)printf(the list is empty,no elementn);elseif(lst-head=lst-tail)printf(only one element:%cn,lst-head-info);free(lst-head);lst-head=lst-tail=0;elsepnode p=lst-tail;if(n11)for(int i=0;i!=n1-1;+i)p=p-next;lst-tail=p;lst-head

4、=p-next;if(n2=1)while(!isempty(lst)if(lst-head=lst-tail)printf(%c ,lst-head-info);free(lst-head);lst-head=lst-tail=0;break;printf(%c ,lst-head-info);lst-tail-next=lst-head-next;free(lst-head);lst-head=lst-tail-next;printf(n);elsewhile(!isempty(lst)for(int j=0;j!=n2-1;+j)p=p-next;if(lst-head=lst-tail

5、)printf(%c ,lst-head-info);free(lst-head);lst-head=lst-tail=0;break;lst-tail=p;lst-head=p-next;printf(%c ,lst-head-info);lst-tail-next=lst-head-next;free(lst-head);lst-head=lst-tail-next;printf(n);void main()for(int i=0;i!=100;+i)plist lst=creat_list();int n1,n2,n3;char info1,c; printf(nninput the e

6、lement accoutn); scanf(%d,&n1);printf(input the frist positionn);scanf(%d,&n2);printf(input the position you want to deleten);scanf(%d%*1c,&n3);system(cls);printf(input all the informmation);for(int j=0;j!=n1;+j) scanf(%c%*1c,&info1);add_to_tail(lst,info1);fun(lst,n2,n3);printf(n双击回车继续,+号结束、n);scanf(%c*%1c,&c);if(c=+)exit(0);if(c=n)continue;

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 科普知识


经营许可证编号:宁ICP备18001539号-1