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.

Recommended Answers

All 5 Replies

Initialise countPtr

Then
countPtr = countPtr->next;

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 ++;
	}
}

Are you asking, or did you compile it and try it?

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.