📄 ring.cpp
字号:
#include<iostream.h>
#include<iomanip.h>
#include"ring.h"
Ring::Ring(int n)
{
pBegin=new Boy[n];
pCurrent=pBegin;
for(int i=1;i<=n;i++,pCurrent=pCurrent->next)
{
pCurrent->next=pBegin+i%n;
pCurrent->code=i;
PutBoy();
} //循环结束时,pCurrent指向第一个小孩
Display(); //打印初始时所有小孩
pCurrent=&pBegin[n-1];//当前小孩位置在最后一个编号
}
void Ring::Count(int m)
{
for(int i=0;i<m;i++)
{
pivot=pCurrent;
pCurrent=pivot->next;
}
}
void Ring::PutBoy()
{
static int numInLine;
if(numInLine++%10==0)
cout<<endl;
cout<<setw(4)<<pCurrent->code;
}
void Ring::ClearBoy()
{
pivot->next=pCurrent->next;
pCurrent=pivot;
}
void Ring::Display()
{
Boy* pB=pCurrent;
do{
PutBoy();
pCurrent=pCurrent->next;
}while(pB!=pCurrent);
cout<<endl;
}
Ring::~Ring()
{
delete[]pBegin;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -