数据结构实验课五-1

#include<iostream>
using namespace std;

const int QueueSize = 100;
template<typename DataType>
class CirQueue
{
public:
CirQueue();
~CirQueue();
void EnQueue();
DataType DeQueue();
int Empty();
private:
DataType data[QueueSize];
int front, rear;
};

template<typename DataType>
CirQueue<DataType>::CirQueue()
{
rear = front = QueueSize -1;
}

template<typename DataType>
CirQueue<DataType>::~CirQueue(){}

template<typename DataType>
CirQueue<DataType>::Empty()
{
if(rear == front)
{
printf("Null");
}
}
template<typename DataType>
void CirQueue<DataType>::EnQueue()
{
int b;
cout<<"请输入要入队的数字："<<endl;
cin>>b;
if ((rear + 1) % QueueSize == front)throw"上溢";
rear = (rear + 1) % QueueSize;
data[rear] = b;
}

template<typename DataType>
DataType CirQueue<DataType>::DeQueue()
{
if (rear == front)throw"下溢";
front = (front + 1) % QueueSize;
cout<<"出队的元素是："<<endl;
cout<<data[front]<<endl;
}

template<typename DataType>
{
if (rear == front)throw"下溢";
return data[(front + 1) % QueueSize];
}

int main()
{
int x;
int c = 0;
CirQueue<int> Q;
int a;
while(1){
cout<<"请选择功能："<<endl;
cout<<"1:入队"<<endl;
cout<<"2:出队"<<endl;
cout<<"0:退出"<<endl;
cin>>x;
switch (x)
{
case 0: return 0;break;
case 1:Q.EnQueue();c = c+1;break;
case 2:c = c-1;if(c == -1){cout<<"队列为空！";return 0;}Q.DeQueue();break;
default:cout<<"输入错误，重新输入！"<<endl;
}
}
return 0;
}



09-26 4952
10-16 56

01-25 3162
06-03 8602
11-23
06-18 1593
05-23 116
10-17 2万+
03-26 1953
01-18
09-28