我正在尝试制作一个模拟器类,它将使用队列将列车从列车中添加到队列中,因此它将成为车队队列。运输也是火车类的数据类型。使用队列类来排列列车的车厢 - C++
我将使用一种方法在列车到达时排队,将它们添加到不同的队列中。一旦他们的货物卸货,我也会有一种方法让列车出列。
我有一列火车类有一个私有变量:
LinkedList<Carriage> *list;
Queue类有一个私有变量:
LinkedList<dataType> *list;
在我的演示文件,我呼吁:
Train* train1; //declare a train.
train1 = new Train(arr); //instantiate train with an array of integers
Queue<Carriage> queue1; //declare a queue.
queue1 = new Queue<Carriage>(train1); //instantiate queue with train data.
我遇到了我的队列类问题,我不太确定如何实现它。
我的队列class.h:
template <typename dataType> //dataType
class Queue
{
public:
Queue();
Queue(dataType arr[]);
~Queue();
void pop();
void push(dataType data);
private:
LinkedList<dataType> *list;
};
#include "Queue.template"
//there is also a namespace and a macroguard, left them out of this.
编辑 - 没有添加足够的信息。
在上面的演示文件代码中,我希望能够调用queue1 = new Queue(train1);
当我这样做时,我得到错误,所以我知道我做错了我的构造函数,因为它们都是linkedlists,我需要使用循环将车厢分配到队列吗?
我需要帮助的是让火车车厢进入队列。
谢谢:)
有什么问题? – crazyjul
那么你的问题是什么? – 2011-10-07 12:00:24
您需要提出更具体的问题。 “我不确定如何实施”并不是非常具体。你有什么尝试?你想要什么样的建议? – Mat