?? queue.h
字號:
//queue.h
#ifndef QUEUE_CLASS
#define QUEUE_CLASS
#include <iostream>
#include <cstdlib>
using namespace std;
#include "link.h"
template <class T>
class Queue
{
private:
// 用于存放隊列的鏈表對象
LinkedList<T> queueList;
public:
// 構造函數
Queue(void);
// 隊列存取方法
void QInsert(const T& elt);
T QDelete(void);
// 隊列訪問
T QFront(void);
// 隊列監測方法
int QLength(void) const;
int QEmpty(void) const;
void QClear(void);
};
// 構造函數
template <class T>
Queue<T>::Queue(void)
{}
// 鏈表類成員函數ListSize返回鏈表長度
template <class T>
int Queue<T>::QLength(void) const
{
return queueList.ListSize();
}
// 鏈表類成員函數ListEmpty測試隊列空否
template <class T>
int Queue<T>::QEmpty(void) const
{
return queueList.ListEmpty();
}
// 鏈表類成員函數ClearList 清空隊列
template <class T>
void Queue<T>::QClear(void)
{
queueList.ClearList();
}
// 鏈表類成員函數InsertRear在隊尾插入一項
template <class T>
void Queue<T>::QInsert(const T& elt)
{
queueList.InsertRear(elt);
}
// 鏈表類成員函數DeleteFront從隊首刪除一項
template <class T>
T Queue<T>::QDelete(void)
{
// 測試隊列空否,若空則中止
if (queueList.ListEmpty())
{
cerr << "Calling QDelete for an empty queue!" << endl;
exit(1);
}
return queueList.DeleteFront();
}
// 返回隊首元素的數值
template <class T>
T Queue<T>::QFront(void)
{
// 測試隊列空否,若空則中止
if (queueList.ListEmpty())
{
cerr << "Calling QFront for an empty queue!" << endl;
exit(1);
}
// 重新設置隊頭并返回其值
queueList.Reset();
return queueList.Data();
}
#endif // QUEUE_CLASS
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -