⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ring.cpp

📁 上面的程序是关于钱能的C++课后习题答案
💻 CPP
字号:
//********************
//**    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];     //当前小孩位置在最后一个编号
  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;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -