?? ring.cpp
字號:
//********************
//** ring.cpp **
//********************
#include <iostream.h>
#include <iomanip.h>
#include "ring.h"
Ring::Ring(int n)
{
pBegin=new Boy[n]; //分配小孩結(jié)構(gòu)數(shù)組
pCurrent=pBegin;
for(int i=1; i<=n; i++,pCurrent=pCurrent->next){
pCurrent->next = pBegin+i%n; //將結(jié)點鏈起來
pCurrent->code=i; //小孩編號
//PutBoy();
}
cout <<endl;
pCurrent=&pBegin[n-1]; //當(dāng)前小孩位置在最后一個編號
Display();
}
void Ring::Count(int m)
{
for(int i=1; i<=m; i++){
pivot = pCurrent;
pCurrent = pCurrent->next;
}
}
void Ring::PutBoy() const
{
static int numInLine;
if(numInLine++%18==0)
cout <<endl;
cout <<setw(4) <<pCurrent->code;
}
void Ring::ClearBoy()
{
pivot->next=pCurrent->next;
}
Ring::~Ring()
{
delete[]pBegin;
}
void Ring::Display()
{
Boy* pB = pCurrent->next;
if(!pB) return;
do{
pCurrent = pCurrent->next;
PutBoy();
}while(pB!=pCurrent->next);
cout <<endl;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -