#include <iostream>
using namespace std;
int poporder = 0;
class node
{
friend class Queue; //友元类
private:
long data;
node * next; //递归定义指向后继结点的指针
};
class Queue
{
public:
Queue();
~Queue();
void destroy(); //销毁一个队列
bool push(long item); //把数据压进队列
bool pop(); //出队列
private:
node *rear;
node *front;
int Queuelenth; //当前队列长度
};
Queue::Queue()
{
rear = new node;
rear->next = NULL;
front = rear;
Queuelenth = 0;
}
Queue::~Queue()
{
destroy();
delete rear;
delete front;
}
void Queue::destroy()
{
for(int i = 0;i < Queuelenth; i++ )
{
pop();
}
}
/********入队列*******/
bool Queue::push(long item)
{
node *newnodep = new node;
newnodep->data = item;
rear->next = newnodep;
rear = newnodep;
Queuelenth++;
return true;
}
/******出队列********/
bool Queue::pop()
{
if(Queuelenth == 0)
return false;
node *popnodep = front->next;
front = front->next;
Queuelenth--;
return true;
}
链队
最新推荐文章于 2022-07-03 10:41:26 发布