Joseph问题(循环链表)
来源:互联网 发布:斗鱼主播用的唱歌软件 编辑:程序博客网 时间:2024/05/16 09:55
- #include<iostream.h>
- struct student
- {
- int rank;
- student *next;
- };
- student *final;
- student *creat(int i)
- {
- student *head,*p1,*p2;
- int n=1;
- p1=new(student);
- head=p1;
- p2=p1;
- p1->rank=n;
- cout<<"Construct the "<<n<<"th unit"<<endl<<endl;
- while(n!=i)
- {
- ++n;
- p1=new(student);
- p1->rank=n;
- cout<<"Construct the "<<n<<"th unit"<<endl<<endl;
- p2->next=p1;
- p2=p1;
- }
- delete(p1);
- p2->next=head;
- return head;
- }
- void fun(student *head,int j)
- {
- student *p;
- student *n;
- n=head;
- if(n==n->next)
- { final=n->next;
- return;
- }
- int round=j;
- while(round)
- {
- round--;
- p=n;
- n=p->next;
- }
- p->next=n->next;
- cout<<"Delete the "<<n->rank<<"th unit"<<endl<<endl;
- delete n;
- fun(p->next,j);
- }
- int main()
- {
- student *head1;
- int i,j;
- cout<<"Please input the number:";
- cin>>i;
- head1=creat(i);
- cout<<"Please input the key:";
- cin>>j;
- fun(head1,j);
- cout<<"Remaining the "<<final->rank<<"th unit"<<endl;
- return 0;
- }
- Joseph问题(循环链表)
- 循环链表实现Joseph环(约瑟夫环)猴子选大王类似问题
- Joseph环-循环链表实现
- (2011.11.20)02_循环链表举例_约瑟夫(Joseph)环问题.cpp
- 用单向循环链表解决约瑟夫环(Joseph)问题
- 约瑟夫(Joseph)问题
- 【Joseph问题】poj1012 Joseph
- Joseph环(顺序表、链队列)
- joseph问题
- joseph问题
- Joseph问题
- {joseph问题}
- Joseph问题
- Joseph问题
- 数据结构—线性表--Joseph问题
- poj 1012 Joseph (约瑟夫问题)
- Joseph Problem(解约瑟夫问题)
- 算法题-约瑟夫(Joseph)问题求解
- 关于java桌面应用程序在现在的领域中有何广泛的前景?
- 打台球的男人
- 【转】程序员必知必会之blog篇
- 【转】常写博客的好处
- 更清晰的DirectX程序结构(基于DirectInput实验)
- Joseph问题(循环链表)
- 使用缓冲数据的DirectInput来控制游戏
- 共享Java电子书
- (转)40种网页常用小技巧技巧
- (转)验证码的破解思路!
- 关于time_t类型的学习
- Linux下两个实用命令:which和whereis 的区别
- C语言中的time.h 文件的全面学习(转)
- 啊啊啊