943,840 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1173
  • C++ RSS
Oct 21st, 2008
0

A little help traversing through a queue please

Expand Post »
All this function is supposed to do is count each node in the queue and return the number of nodes.
c++ Syntax (Toggle Plain Text)
  1. template<class SomeType>
  2. int TemplateQ<SomeType>::Size() const
  3. {
  4. int numberOfChars = 0;
  5. QueueNode<SomeType>* countPtr;
  6.  
  7. if(IsEmpty)
  8. return 0;
  9. while(countPtr != rearPtr)
  10. {
  11. countPtr = frontPtr->data;
  12.  
  13. numberOfChars ++;
  14. }
  15. }

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.
Last edited by JustLearning; Oct 21st, 2008 at 3:38 pm.
Reputation Points: 10
Solved Threads: 0
Light Poster
JustLearning is offline Offline
31 posts
since Sep 2008
Oct 21st, 2008
0

Re: A little help traversing through a queue please

Initialise countPtr

Then
countPtr = countPtr->next;
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Oct 21st, 2008
0

Re: A little help traversing through a queue please

Click to Expand / Collapse  Quote originally posted by Salem ...
Initialise countPtr

Then
countPtr = countPtr->next;
so then will this work
c++ Syntax (Toggle Plain Text)
  1. template<class SomeType>
  2. int TemplateQ<SomeType>::Size() const
  3. {
  4. int numberOfChars = 0;
  5. QueueNode<SomeType>* countPtr;
  6.  
  7. if(IsEmpty)
  8. return 0;
  9. while(countPtr != frontPtr)
  10. {
  11. countPtr = lastPtr->data;
  12. countPtr = countPtr->nextPtr;
  13. numberOfChars ++;
  14. }
  15. }
Reputation Points: 10
Solved Threads: 0
Light Poster
JustLearning is offline Offline
31 posts
since Sep 2008
Oct 21st, 2008
0

Re: A little help traversing through a queue please

Are you asking, or did you compile it and try it?
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Oct 21st, 2008
0

Re: A little help traversing through a queue please

ok I was asking because my driver program was not written yet and I have no way of checking it without it.
Last edited by JustLearning; Oct 21st, 2008 at 4:54 pm.
Reputation Points: 10
Solved Threads: 0
Light Poster
JustLearning is offline Offline
31 posts
since Sep 2008
Oct 21st, 2008
0

Re: A little help traversing through a queue please

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.
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: C++ Logic Fuction Error
Next Thread in C++ Forum Timeline: Having trouble with a loop.(For a class)





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC