代码拉取完成,页面将自动刷新
#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;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。