I am attempting make a simulator class that will use a Queue to add the Carriages from Train in to a Queue, so it will become a Queue of carriages. Carriage is also the dataType of the train class.
I will use a method to enqueue trains as they arrive, adding them to different queues. I will also have a method to dequeue trains once their cargo has been unloaded.
I have a Train class which has a private variable of:
LinkedList<Carriage> *list;
Queue class has a private variable of:
LinkedList<dataType> *list;
In my demo file I am calling:
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.
I am having a problem with my queue class, I am not quite sure on how to implement it.
My Queue 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.
EDIT – Did not add enough information.
In the above demo file code, I want to be able to call queue1 = new Queue(train1);
When I do this I get errors so I know I’m doing something wrong with my constructor, as they are both linkedlists, do i need to use a loop to assign the carriages in to the queue?
What I need help with is getting the train carriages in to the queue.
Thanks 🙂
You are passing argument of type
LinkedListto a constructor takes argument of array ofdatatype, which causes the error.You can, however, loop through every
train1element, andpushit to theQueue.As a note,
pushandpopare function names for thestack.Queuehasenqueueanddequeue