0

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
{
public:
	const queueType& operator=(const queueType<Type>&);
	void addQueue(const Type& queueElement);
	void deleteQueue();
	queueType(int queueSize = 100);
	queueType(const queueType<Type>& otherQueue);
	~queueType();

private:
	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);

		intQ.initializeQueue();

                                copy = intQ;
		work = intQ;


		if (select == 2)
		{
		copy = intQ;
		cout << "The Queue contains: ";
		while(!copy.isEmptyQueue())
		{
		cout<< copy.front() <<" ";
		copy.deleteQueue();
		}
                                }

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

Thanks

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by dougy83
0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.