📄 lqueue.h
字号:
//--------------------------//
// //
// 链队列类 //
// //
//--------------------------//
#if !defined(_INC_LQUEUE_OO)
#define _INC_LQUEUE_OO
#include<stdlib.h>
#include"D:\vc_h_file\Node.h"
template<class T>
class LQueue
{
private:
Node<T> *front; //队头指针
Node<T> *rear; //队尾指针
int size; //队列长
public:
LQueue();
~LQueue();
int Size();//队列长
int Empty();//判断队列是否为空
T GetData();//取队头项
void SetData(T item);//更改队头项
void Insert(T item);//入队
T Delete();//出队
void Clear();//置空队
};
template<class T>
LQueue<T>::LQueue()
{
front=new Node<T>;
if(front==NULL)
{
cerr<<"overflow"<<endl;
exit(1);
}
rear=front;
size=0;
}
template<class T>
LQueue<T>::~LQueue()
{
while(front->NextNode()!=NULL)
front->DeleteAfter();
delete front;
}
template<class T>
int LQueue<T>::Size()
{
return(size);
}
template<class T>
int LQueue<T>::Empty()
{
if(size==0)
return(1);
return(0);
}
template<class T>
T LQueue<T>::GetData()
{
Node<T> *ptr;
if(size==0)
{
cerr<<"Queue is empty!\n"<<endl;
exit(1);
}
ptr=front->NextNode();
return(ptr->data);
}
template<class T>
void LQueue<T>::SetData(T item)
{
Node<T> *ptr;
if(size==0)
{
cerr<<"Setting data to an empty LQueue!\n"<<endl;
exit(1);
}
ptr=front->NextNode();
ptr->data=item;
}
template<class T>
void LQueue<T>::Insert(T item)
{
rear->InsertAfter(item);
rear=rear->NextNode();
size++;
}
template<class T>
T LQueue<T>::Delete()
{
Node<T> *ptr;
T item;
if(size==0)
{
cerr<<"Deleting an empty LQueue!\n"<<endl;
exit(1);
}
ptr=front->NextNode();
item=ptr->data;
front->DeleteAfter();
size--;
if(size==0)
rear=front;
return(item);
}
template<class T>
void LQueue<T>::Clear()
{
while(front->NextNode()!=NULL)
front->DeleteAfter();
rear=front;
size=0;
}
#endif //_INC_LQUEUE_OO
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -