2011-10-07 77 views
0

我正在尝试制作一个模拟器类,它将使用队列将列车从列车中添加到队列中,因此它将成为车队队列。运输也是火车类的数据类型。使用队列类来排列列车的车厢 - 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,我需要使用循环将车厢分配到队列吗?

我需要帮助的是让火车车厢进入队列。

谢谢:)

+0

有什么问题? – crazyjul

+0

那么你的问题是什么? – 2011-10-07 12:00:24

+0

您需要提出更具体的问题。 “我不确定如何实施”并不是非常具体。你有什么尝试?你想要什么样的建议? – Mat

回答

0

你传入LinkedList类型的参数传递给一个构造函数采用的datatype阵列,这会导致错误的参数。

但是,您可以循环访问每个train1元素,并将push循环到Queue

作为说明,pushpopstack的函数名称。 Queue已有enqueuedequeue

+0

我在某处读到新的C++库对栈和队列使用push和pop。 那么你是否说我需要改变构造函数来接受列车对象,然后在构造函数循环中通过列车中的每个位置将它推入队列? – cheeseman