i have an assignment I've completed except for copying a queue into another queue. According to the book the code for copying is almost the same for a stack, but when I tell my program that copy = original, it's blank. Here is the code I have so far.

BTW I know it's not 100% complete but that portion I haven't done is irrelevent to my problem.

header file

#include <iostream>
#include <cassert>

template<class Type>
class queueType
	const queueType& operator=(const queueType<Type>&);
	void addQueue(const Type& queueElement);
	void deleteQueue();
	queueType(int queueSize = 100);
	queueType(const queueType<Type>& otherQueue);

	int maxQueueSize;
	int count;
	int queueFront;
	int queueRear;
	Type *list;
	void copyQueue(const queueType<Type>& otherQueue);

template<class Type>
void queueType<Type>::copyQueue(const queueType<Type>& otherQueue)
	delete [] list;
	maxQueueSize = otherQueue.maxQueueSize;
	queueFront = otherQueue.queueFront;
	queueRear = otherQueue.queueRear;
	list = new Type[maxQueueSize];
	assert (list != NULL);

	for(int j = 0; j < queueFront; j++)
		list[j] = otherQueue.list[j];

And here is my main program

cout << "How big do you want your queue to be?" << endl;
		cin >> size;

		queueType<int> intQ(size);
		queueType<int> copy(size);
		queueType<int> work(size);


                                copy = intQ;
		work = intQ;

		if (select == 2)
		copy = intQ;
		cout << "The Queue contains: ";
		cout<< copy.front() <<" ";

I only posted the relevent code, so if you need anymore let me know.


Try copying all the list items, not just the ones before queueFront - generally queues wrap, it's simpler to just copy everything.

This article has been dead for over six months. Start a new discussion instead.