这个问题怎么解决
const int maxSize=50;
template <class E>
class Queue {
public:
Queue() { }; //构造函数
~Queue() { }; //析构函数
virtual bool EnQueue(E x) = 0; //进队列
virtual bool DeQueue(E& x) = 0; //出队列
virtual bool getFront(E& x) = 0; //取队头
virtual bool IsEmpty() const = 0; //判队列空
virtual bool IsFull() const = 0; //判队列满
// void MakeEmpty(){front=rear=0;}
};
#include <iostream.h>
#include "Queue.h"
template <class E>
class LinkedQueue:public Queue<E> {
public:
LinkedQueue() : rear(NULL), front(NULL) { }
~LinkedQueue(){delete[] elements;}
bool EnQueue(const E& x);
bool DeQueue(E& x);
bool GetFront(E& x) const;
void makeEmpty(){front=rear=0;} //实现与~Queue()同
bool IsEmpty() const { return (front == NULL)?true:false; }
int getSize()const;
friend ostream& operator <<(ostream& os,LinkedQueue<E>& Q);{
protected: QueueNode <E> *front, *rear;
};
template <class E>
LinkedQueue<E>::~LinkedQueue() {
QueueNode<E> *p;
while (front != NULL) {
p = front; front = front->link; delete p;
}
};//逐个删除队列结点
template <class E>
bool LinkedQueue<E>::EnQueue(const E& x) {
if (front == NULL) {
front = rear = new QueueNode<E> (x);
if (front == NULL) return false; }
else {
rear->link = new QueueNode<E> (x);
if (rear->link == NULL) return false;
rear = rear->link;
}
return true;
};//链式队列的入队操作
template <class E>
bool LinkedQueue<E>::DeQueue(E& x) {
if (IsEmpty() == true) return false;
QueueNode<E> *p = front;
x = front->data; front = front->link;
delete p; return true;
};//链式队列的出队操作
template <class E>
bool LinkedQueue<E>::GetFront(E& x)const {
if (IsEmpty() == true) return false;
x = front->data; return true;
};//链式队列取队头元素操作
template<class E>
int LinkedQueue<E>::getSize()const {
QueueNode<E> *p=front;int k=0;
while (p!=NULL){p=p->link;k++;}
return k;
};
template<class E>
friend ostream& operator <<(ostream& os,LinkedQueue<E>& Q){
os<<"队列中元素个数有"<<Q.getSize()<<endl;
QueueNode<E> *p=Q.front;int i=0;
while (p!=NULL){
os<<++i<<","<<p->data<<endl;}
return os;
};//元素的重载
void main()
{
int maxSize,number,i,select=5;
char s;
cout<<"\n请输入对的大小:"<<endl;
cin>>maxSize;
LinckedQueue<char> LinkedQueue(maxSize);
while(select!=4)
{
cout<<"\n\t\t\t************操作菜单*****************\n";
cout<<"\t\t\t\t 1 入队"<<endl;
cout<<"\t\t\t\t 2 出队"<<endl;
cout<<"\t\t\t\t 3 取队头元素"<<endl;
cout<<"\t\t\t\t 4 退出"<<endl;
cout<<"\t\t\t************请选择序号*****************\n";
cin>>select;
switch(select)
{
case 1:
cout<<"请输入一个队列并以.结束"<<endl;
cin>>s;
while(s!='.')
{
LinkedQueue.EnQueue(s);
cin>>s;
}
break;
case 2:
cout<<"请输入出队字符数:";
cin>>number;
cout<<"\n出队元素依次为:";
for(i=0;i<number;i++)
if (LinkedQueue.DeQueue(s)) cout<<s<<" ";
break;
case 3:
if (!LinkedQueue.GetFront(s)){cout<<"队空"<<endl;break;}
cout<<"队头元素为:"<<s;
break;
case 4:
break;
}
}
cout<<"谢谢使用"<<endl;
}