我一直在尝试用c++模拟机场来解决这个队列程序。当我使用下面的队列函数时,程序卡住了,没有给出任何错误消息。我认为错误是在"this->front = newNode;"这行,但我不能找出更多的东西。
提前感谢!
bool Queue::enqueue(Plane p) {
Node *newNode = new Node;
newNode->priority = 6 - p.getFuel();
newNode->plane = p;
newNode->next = 0;
if (this->length < 6) {
if (this->length == 0) {
this->front = newNode;
} else {
cout << "this->length != 0n";
this->rear->next = newNode;
}
this->rear = newNode;
this->length++;
return true;
} else {
return false;
}
}
使用标准c++ <模板:
#include <iostream>
#include <queue>
// Substitute your definition here
typedef int Plane;
typedef std::queue <Plane> Runway;
int main()
{
Runway runway;
Plane plane(42);
// En-queue
runway.push(plane);
// Who is ready?
std::cout << runway.front() << std::endl;
// De-queue
runway.pop();
return 0;
}
在您的情况下,您可能需要查看