📄 queue.h
字号:
// Queue.h: interface for the Queue class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_QUEUE_H__F714AF18_D013_4FB1_8FF9_6188690F2D52__INCLUDED_)
#define AFX_QUEUE_H__F714AF18_D013_4FB1_8FF9_6188690F2D52__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
template<class T> class Queue
{
public:
Queue();
~Queue();
public:
T* getHead();
void append(T*);
int getLength();
bool isEmpty();
void clean();
protected:
struct ElementNode
{
ElementNode* next;
T* value;
};
ElementNode *head;
ElementNode *rear;
int length;
};
template <class T>
Queue<T>::Queue()
{
length=0;
rear=head=NULL;
}
template<class T>
Queue<T>::~Queue()
{
while (head!=NULL)
{
ElementNode* temp;
temp=head;
head=head->next;
delete (temp);
}
}
template<class T>
Queue<T>::getLength()
{
return length;
}
template<class T>
bool Queue<T>::isEmpty()
{
if(length==0)
{
return true;
}
else
return false;
}
template<class T>
T* Queue<T>::getHead()
{
if(length==0)
{
return NULL;
}
length--;
ElementNode* temp=head;
T* pele=head->value;
head=head->next;
if(length==0)
{
rear=NULL;
}
delete(temp);
return pele;
}
template<class T>
void Queue<T>::append(T *ele)
{
ElementNode* ptrEle=new ElementNode;
ptrEle->value =ele;
ptrEle->next=NULL;
length++;
if (head==NULL && rear==NULL)
{
head=rear=ptrEle;
return;
}
rear->next=ptrEle ;
rear=ptrEle;
}
template<class T>
void Queue<T>::clean()
{
while (head!=NULL)
{
ElementNode* temp;
temp=head;
head=head->next;
delete (temp);
}
head=rear=NULL;
length=0;
}
#endif // !defined(AFX_QUEUE_H__F714AF18_D013_4FB1_8FF9_6188690F2D52__INCLUDED_)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -