有运行结果,但是一运行就会“停止运行”
#include <iostream>
using namespace std;
//循环队列
class MyQueue
{
private:
int *m_Queue;
int m_Queuelen;
int m_QueueCapacty;
int m_Head;
int m_Tail;
public:
MyQueue(int QueueCapacty)
{
m_QueueCapacty=QueueCapacty;
m_Queue=new int[m_QueueCapacty];
ClearQueue();
}
~MyQueue()
{
delete []m_Queue;
m_Queue=NULL;
}
void ClearQueue()
{
m_Head=0;
m_Tail=0;
m_Queuelen=0;
}
bool QueueEmpty()const
{
if(m_Queuelen==0)
return true;
else
return false;
}
bool QueueFull()const
{
if(m_Queuelen==m_QueueCapacty)
return true;
return false;
}
bool EnQueue(int Elem)
{
if(QueueFull())
return false;
else
{
m_Queue[m_Tail]=Elem;
m_Tail++;
m_Tail=m_Tail%m_QueueCapacty;
m_Queuelen++;
return true;
}
}
int QueueLength()
{
return m_Queuelen;
}
bool DeQueue(int &Elem)
{
if(QueueEmpty())
return false;
else
{
Elem=m_Queue[m_Tail];
m_Head++;
m_Head=m_Head%m_QueueCapacty;
m_Queuelen--;
return true;
}
}
int QueueLength()const
{
return m_Queuelen;
}
void QueueTravers()
{
for(int i=m_Head; i<m_Queuelen+m_Head; i++)
cout<<m_Queue[i%m_QueueCapacty]<<endl;
}
};
int main()
{
MyQueue *p=new MyQueue(4);
p->EnQueue(10);
p->EnQueue(13);
p->EnQueue(11);
p->EnQueue(16);
//p->EnQueue(12);
p->QueueTravers();
int e=0;
p->DeQueue(e);
cout<<endl;
cout<<e<<endl;
p->DeQueue(e);
cout<<endl;
cout<<e<<endl;
p->QueueTravers();
//p->ClearQueue();
// p->EnQueue(22);
//p->EnQueue(33);
//p->QueueTravers();
delete []p;
return 0;
}