📄 ring.cpp.txt
字号:
//***********************************
//**** 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();
} //到这里已经连成了一条线,但是尾巴指向了未知区域
cout<<endl;
pCurrent=&pBegin[n-1]; // 尾巴咬上了头了
}
Displpay();
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 + -