0

All this function is supposed to do is count each node in the queue and return the number of nodes.

template<class SomeType>
int TemplateQ<SomeType>::Size() const
{
	int numberOfChars = 0;
	QueueNode<SomeType>* countPtr;
	
	if(IsEmpty)
		return 0;
	while(countPtr != rearPtr)
	{
		countPtr = frontPtr->data;
		
		numberOfChars ++;
	}
}

I am not sure how I am supposed to traverse through the queue counting each node.

I 2 private class objects frontPtr, and rearPtr to use. am I even close on this? if more information is needed I can put it here.

2
Contributors
5
Replies
6
Views
9 Years
Discussion Span
Last Post by Salem
0

Initialise countPtr

Then
countPtr = countPtr->next;

so then will this work

template<class SomeType>
int TemplateQ<SomeType>::Size() const
{
	int numberOfChars = 0;
	QueueNode<SomeType>* countPtr;
	
	if(IsEmpty)
		return 0;
	while(countPtr != frontPtr)
	{
		countPtr = lastPtr->data;
		countPtr = countPtr->nextPtr;
		numberOfChars ++;
	}
}
0

ok I was asking because my driver program was not written yet and I have no way of checking it without it.

0

So.......
Why don't you have a compiler on your home machine?

There's plenty of good and free ones to choose from, and it'll save you a lot of time by being able to try things yourself whenever you feel like it.

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.