11-5.cpp

来自「为初学者提供的最佳的C++程序设计源程序库」· C++ 代码 · 共 60 行

CPP
60
字号
#include<iostream.h>
#include<process.h>
const MAX =200;
class queue 
{
protected:
    int qdata[MAX];
    int tail,head;
public:
   queue(void)
   {
     tail=head=0;
   }
   void pushta(int i)
   {
    tail++;
    qdata[tail]=i;
    cout<<"tail="<<tail<<endl;
  }
   int pophe(void)
   {
	   head++;
	   cout<<"head="<<head<<endl;
	   return qdata[head];
   }
};
class queue2:public queue
{
public:
   void pushta(int i)
   {
     if(tail<MAX)
     queue::pushta(i);
     else
     {
      cout<<"queue is full\n";
      return;
      }
    }
    int pophe(void)
    {
     if(head<tail)
        return queue::pophe();
      else
       {
         cout<<"queue underflow\n";
         exit(1);
       }
     }
};
void main(void)
{
  queue2 q;
  q.pushta(123);
  q.pushta(456);
  cout<<"1:"<<q.pophe()<<endl;
  cout<<"2:"<<q.pophe()<<endl;
  cout<<"3:"<<q.pophe()<<endl;
}

⌨️ 快捷键说明

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