#include usingnamespacestd;structchild{intnum;child*link;};;voidinit(intn);;voidgameStart(intn,intm);child*head;child*present;child*end;;intmain(){intn,m;cout<<"请输入孩子的个数:";cin>>n;cout<<"请输入正整数m:";cin>>m;init(n);gameStart(n,m);cout<<"第"<num<<"个孩子将获得胜利!"< deletepresent; return0;}voidinit(intn){head=newchild;head->num=1;present=head;for(inti=1;i{ present->link=newchild;present->link->num=i+1;present=present->link;}present->link=head;end=present;present=head;}voidgameStart(intn,intm){child*pGuard=end;while(n!=1){for(intj=1;j{ pGuard=present;present=present->link;}pGuard->link=present->link;deletepresent;present=pGuard->link;n--;}}这是个约瑟夫环问题我想问下present->link=head;end=present;present=head;具体什么意思貌似是将首尾相连形成循环链表吧。。请详细解释下。。谢谢!求解。。
噜噜哒
万千封印
相关分类