#include <iostream>using namespace std;template<class T,int MaxSize>class SeqQueue{T data[MaxSize];int front, rear;public:SeqQueue(T a[],int n);void EnQueue(T x);T DeQueue();T GetQueue();bool Empty();};template<class T,int MaxSize>SeqQueue<T,MaxSize>::SeqQueue(T a[],int n){rear=0;front=0;}template<class T,int MaxSize>void SeqQueue<T,MaxSize>::EnQueue(T x){if(rear==MaxSize){cerr<<"上溢";exit(1);}rear=rear+1;data[rear]=x;}template<class T,int MaxSize>T SeqQueue<T,MaxSize>::DeQueue(){if(rear==front){cerr<<"无元素可取";exit(1);}front=front+1;return data[front];}template<class T,int MaxSize>T SeqQueue<T,MaxSize>::GetQueue(){if(front==rear){cerr<<"无元素可取";exit(1);}return data[front];}template<class T,int MaxSize>bool SeqQueue<T,MaxSize>::Empty(){if(front==rear)return 1;elsereturn 0;}int main(){int a[5]={1,2,3,4,5};int n=5,m;SeqQueue<int,5> queue1(a,n);for(int i=0;i<n;i++)queue1.EnQueue(a[i]);for(int i=0;i<n;i++){m=queue1.DeQueue();cout<<m<<'\t';}m=queue1.Empty();cout<<m<<endl;cin>>m;return 0;}求大神知道一下小妹啊,小妹暑假在预习数据结构
1 回答
LEATH
TA贡献1936条经验 获得超6个赞
template<class T,int MaxSize>
void SeqQueue<T,MaxSize>::EnQueue(T x)
{
if(rear==MaxSize)
{cerr<<"上溢";exit(1);}
data[rear++]=x;
}
template<class T,int MaxSize>
T SeqQueue<T,MaxSize>::DeQueue()
{
if(rear==front)
{cerr<<"无元素可取";exit(1);}
return data[front++];
}
- 1 回答
- 0 关注
- 115 浏览
添加回答
举报
0/150
提交
取消