lqueue.h
来自「构造接受语言{{}}的一台自动机」· C头文件 代码 · 共 77 行
H
77 行
#ifndef LQUEUE_H
#define LQUEUE_H
#include"link3.h"
//#include"binnodeptr1.h"
#include<iostream.h>
template <class Elem>class LQueue
{
private:
Link<Elem>* front;
Link<Elem>* rear;
int size;
public:
LQueue()
{front=NULL;rear=NULL;size=0;}
~LQueue()
{clear();}
void clear()
{
while(front!=NULL)
{
rear=front;
front=front->next;
delete rear;
}
rear=NULL;
size=0;
}
bool enqueue(const Elem& it)
{
if(rear==NULL)
front=rear=new Link<Elem>(it,NULL);
else
{ rear->next=new Link<Elem>(it,NULL);
rear=rear->next;
}
size++;
return true;
}
bool dequeue(Elem& it)
{
if(size==0)return false;
it=front->element;
Link<Elem>*ltemp=front;
front=front->next;
delete ltemp;
if(front==NULL)
rear=NULL;
size--;
return true;
}
bool frontValue(Elem& it)const
{
if(size==0)return false;
it=front->element;
return true;
}
void print()
{ Link<Elem>* temp=front;
while(temp!=NULL)
{
cout<<temp->element;
temp=temp->next;
}
}
virtual int length() const {return size;}
};
#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?