#include<iostream>
using namespace std;
struct LinkNode
{
int data;
LinkNode *Next;
};
class LinkQueue
{
private:
LinkNode *front;
LinkNode *rear;
public:
LinkQueue();
~LinkQueue();
void Append(const int &e);
void Remove();
void Traverse();
};
LinkQueue::LinkQueue()
{
front=rear=new LinkNode();
rear->Next=NULL;
}
LinkQueue::~LinkQueue()
{
LinkNode *p=front->Next;
LinkNode *q;
while(p)
{
q=p;
delete p;
p=q->Next;
}
delete front;
}
void LinkQueue::Append(const int &e)
{
LinkNode *p=new LinkNode;
p->data=e;
p->Next=NULL;
if(front->Next==NULL)
{
front->Next=p;
rear=p;
}
else
{
rear->Next=p;
rear=p;
}
}
void LinkQueue::Remove()
{
LinkNode *p=front->Next;
if(p->Next!=NULL)
front->Next=p->Next;
}
void LinkQueue::Traverse()
{
LinkNode *p=front->Next;
while(p)
{
cout<<p->data<<" ";
p=p->Next;
}
}
void main()
{
LinkQueue *l=new LinkQueue();
l->Append(5);
l->Append(4);
l->Append(3);
l->Append(2);
l->Append(1);
l->Remove();
l->Remove();
l->Traverse();
//delete l;
}
慕移动6052691
相关分类