关于链表

expresion 2003-08-20 03:00:31
#include<iostream.h>
#include<iomanip.h>
#include<stdio.h>

struct jose
{
int code;
jose* next;
};

void main()
{
int numOfBoys,interval;
cout<<"please input the number of boys,\n"
<<" interval of counting :\n";
cin>>numOfBoys>>interval;

jose* pJose=new jose[numOfBoys];
jose* pCurrent=pJose;

int itemsInLine=0;

for(int i=1;i<=numOfBoys;i++)
{
pCurrent->next=pJose+i%numOfBoys;
pCurrent->code=i;
pCurrent=pCurrent->next;
if(itemsInLine++ % 10 == 0)
cout<<endl;
cout<<setw(4)<<i;
}
itemsInLine=0;

jose* pivot;
pCurrent=&pJose[numOfBoys-1];

while(pCurrent->next!=pCurrent)
{
for(int j=0;j<interval;j++) //如果interval=3,那pCurrent只是是第几结点
{
pivot=pCurrent;
pCurrent = pivot->next;
}

if(itemsInLine++ % 10 == 0)
cout<<endl;
cout<<setw(4)<<pCurrent->code;
pivot->next=pCurrent->next;
pCurrent=pivot;
}

cout<<"\n\nthe winner is"
<<pCurrent->code<<endl;

delete[]pJose;
getchar();
}
...全文
21 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
98440622 2003-08-20
  • 打赏
  • 举报
回复
我用vc分析,从(环)连表地址上看是指向最后一个节点。
expresion 2003-08-20
  • 打赏
  • 举报
回复
不是吧
jack_wq 2003-08-20
  • 打赏
  • 举报
回复
第五个(假设头节点是第一个)
expresion 2003-08-20
  • 打赏
  • 举报
回复
for(int j=0;j<interval;j++) //如果interval=3,那pCurrent只是是第几结点
{
pivot=pCurrent;
pCurrent = pivot->next;
}
pzytony 2003-08-20
  • 打赏
  • 举报
回复

什么问题???

69,369

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧