链队列——链式存储结构
来源:互联网 发布:面板数据 编辑:程序博客网 时间:2024/05/01 05:35
#include <iostream>
#include <cstdlib>
using namespace std;
//连队的结点
struct Node{
int date;
Node *next;
};
class Queue{
public:
Queue();
~Queue();
bool EnQueue(int e);
bool DeQueue(int &e);
int GetFront();
void ClearQueue();
bool IsEmpty();
private:
Node *Front, *Rear;
};
//构造队列
Queue::Queue(){
Front = Rear = new Node;//头结点
Front->next = NULL;
}
//销毁队列
Queue::~Queue(){
ClearQueue();
delete Front;
}
//入队
bool Queue::EnQueue(int e){
Rear->next = new Node;
Rear = Rear->next;
Rear->date = e;
Rear->next = NULL;
return true;
}
//出队
bool Queue::DeQueue(int &e){
Node *p;
if(!IsEmpty()){
p = Front->next;
e = p->date;
Front->next = p->next;
delete p;
return true;
}else{
cout << "队列为空!" << endl;
return false;
}
}
bool Queue::IsEmpty(){
return Front->next == NULL;
}
//取头结点
int Queue::GetFront(){
if(!IsEmpty()){
return Front->next->date;
}else{
cout << "队列为空,没有头元素!" << endl;
}
}
//清空队列
void Queue::ClearQueue(){
Rear = Front->next;
while(Front->next != NULL){
Front->next = Rear->next;
delete Rear;
Rear = Front->next;
}
Rear = Front;
}
int main(){
Queue q;
int e;
q.DeQueue(e);
q.EnQueue(1);
q.EnQueue(2);
q.EnQueue(3);
q.DeQueue(e);
cout << "e: " << e;
q.~Queue();
system("pause");
return 0;
}
- 链队列——链式存储结构
- 单链队列——队列的链式存储结构
- 队列——链式存储结构
- 队列——链式存储结构及其基本运算(链队列的另一种表达方式)
- 数据结构——队列的链式存储结构以及实现
- 队列——链式存储结构及其基本运算
- 数据结构六—队列的链式存储结构
- 队列---链队列:队列的链式存储结构
- 队列——链式存储
- 队列的链式存储结构
- 队列的链式存储结构
- 队列的链式存储结构
- 队列的链式存储结构
- 队列的链式存储结构
- 队列的链式存储结构
- 队列的链式存储结构
- 队列的链式存储结构
- 队列的链式存储结构
- stamp 邮票设计 搜索02
- Jmeter使用CSV Data Set Config参数化数据不重复的多次循环执行(实现多用户多次抽奖功能)
- java数据类型
- 20161017
- CodeForces 731
- 链队列——链式存储结构
- 【人工神经网络ANN】- 1 - 概览
- 第八天
- C菜鸟日记(1)
- acm-icpc大连站随笔
- [leetcode]15. 3Sum
- HDU 2136 Largest prime factor
- idea配置
- 第九天