4 Star 0 Fork 0

黄家宝/MyElevator

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Queue.cpp 1.33 KB
一键复制 编辑 原始数据 按行查看 历史
黄家宝 提交于 2021-08-05 21:37 . my first commit
#include "Elevator.h"
#include <iostream>
#include<iomanip>
using namespace std;
Queue::Queue() {
//构造一个空队列
this->front = this->rear = new PassengerList();
this->QueueLength = 0;
}
int Queue::InitQueue() {
//初始化队列
this->front = this->rear = new PassengerList;
if (!this->front)
return -1;//分配存储失败
this->front->next = NULL;
this->front->data = NULL;
this->QueueLength = 0;
return 0;
}
int Queue::DestroyQueue() {
//销毁队列Q
while (this->front) {
this->rear = this->front->next;
delete this->front;
this->front = this->rear;
}
return 0;
}
int Queue::EnterQueue(Passenger e) {
//插入元素e为Q的新的队尾元素
PassengerList* p;
p = new PassengerList();
if (!p)
return OVERFLOW;
p->data = e; p->next = NULL;
this->rear->next = p;
this->rear = p;
this->QueueLength++;
return 0;
}
int Queue::DeleteQueue(Passenger& e) { //带头结点的队列
//若队列不空,则删除Q的队头元素,用e返回其值,并返回0;
//否则返回ERROR
PassengerList* p;
if (this->front == this->rear) //如果队列为空,则返回错误
return -1;
p = this->front->next; //绕过头结点
e = p->data;
this->front->data = e;
this->front->next = p->next;
if (this->rear == p)
this->rear = this->front;
delete p;
this->QueueLength--;
return 0;
}
bool Queue::IsQueueEmpty() {
//判断队列是否为空
if (this->front == this->rear)
return 1;
else
return 0;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/Aron_Bao/my-elevator.git
git@gitee.com:Aron_Bao/my-elevator.git
Aron_Bao
my-elevator
MyElevator
master

搜索帮助