A little help traversing through a queue please

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2008
Posts: 31
Reputation: JustLearning is an unknown quantity at this point 
Solved Threads: 0
JustLearning JustLearning is offline Offline
Light Poster

A little help traversing through a queue please

 
0
  #1
Oct 21st, 2008
All this function is supposed to do is count each node in the queue and return the number of nodes.
  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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 751
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: A little help traversing through a queue please

 
0
  #2
Oct 21st, 2008
Initialise countPtr

Then
countPtr = countPtr->next;
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 31
Reputation: JustLearning is an unknown quantity at this point 
Solved Threads: 0
JustLearning JustLearning is offline Offline
Light Poster

Re: A little help traversing through a queue please

 
0
  #3
Oct 21st, 2008
Originally Posted by Salem View Post
Initialise countPtr

Then
countPtr = countPtr->next;
so then will this work
  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. }
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 751
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: A little help traversing through a queue please

 
0
  #4
Oct 21st, 2008
Are you asking, or did you compile it and try it?
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 31
Reputation: JustLearning is an unknown quantity at this point 
Solved Threads: 0
JustLearning JustLearning is offline Offline
Light Poster

Re: A little help traversing through a queue please

 
0
  #5
Oct 21st, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 751
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: A little help traversing through a queue please

 
0
  #6
Oct 21st, 2008
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum


Views: 617 | Replies: 5
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC