#include<iostream>
using namespace std;
class LinkNode
{
public:
LinkNode(int v):m_value(v),m_next(NULL){}
LinkNode():m_next(NULL){}
int m_value;
LinkNode *m_next;
};
class LinkQueue
{
public:
LinkQueue()
{
m_front = m_rear = new LinkNode;
}
~LinkQueue()
{
Clear();
if(m_front != NULL)
{
delete m_front;
m_front = NULL;
}
}
void InQueue(int v)
{
LinkNode *p = new LinkNode(v);
m_rear->m_next = p;
m_rear = p;
}
void OutQueue()
{
if(!IsEmpty())
{
LinkNode *temp = m_front->m_next;
m_front->m_next = temp->m_next;
if(temp==m_rear)
m_rear=m_front;
delete temp;
temp = NULL;
}
}
bool IsEmpty(){return m_rear == m_front ? true : false;}
void Print()
{
LinkNode *p = m_front->m_next;
while(p)
{
cout<<p->m_value<<" ";
p = p->m_next;
}
cout<<endl;
}
void Clear()
{
while(m_front->m_next)
{
OutQueue();
}
}
private:
LinkNode *m_front;
LinkNode *m_rear;
};
数据结构之C++实现链式队列(LinkQueue)(无主函数)
最新推荐文章于 2021-09-05 22:39:26 发布