?? tagseqqueue.h
字號:
#ifndef TAGSEQQUEUE_H
#define TAGSEQQUEUE_H
class TagSeqQueue
{
private:
DataType data[MaxQueueSize];
int front;
int rear;
bool tag;
public:
TagSeqQueue(void)
{front = rear = 0; tag=0;};
~TagSeqQueue(void){};
void Append(const DataType& item); //入隊列
DataType Delete(void); //出隊列
DataType GetFront(void)const; //取隊頭數據元素
int NotEmpty(void)const //非空否
{return tag!=0;};
};
void TagSeqQueue::Append(const DataType& item) //入隊列
//把數據元素item插入隊列作為當前的新隊尾
{
if(rear==front&&tag==1)
{
cout << "隊列已滿!" << endl;
exit(0);
}
data[rear] = item; //把元素item加在隊尾
rear = (rear + 1) % MaxQueueSize; ///隊尾指示器加1
tag=1;
}
DataType TagSeqQueue::Delete(void) //出隊列
//把隊頭元素出隊列,出隊列元素由函數返回
{
if(rear==front&&tag==0)
{
cout << "隊列已空!" << endl;
exit(0);
}
DataType temp = data[front]; //保存原隊頭元素
front = (front + 1) % MaxQueueSize; //隊頭指示器加1
tag=0;
return temp; //返回原隊頭元素
}
DataType TagSeqQueue::GetFront(void)const //取隊頭數據元素
//取隊頭元素并由函數返回
{
if(rear==front&&tag==0)
{
cout << "隊列已空!" << endl;
exit(0);
}
return data[front]; //返回隊頭元素
}
#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -