queue question

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Sep 2008
Posts: 91
Reputation: ezkonekgal is an unknown quantity at this point 
Solved Threads: 1
ezkonekgal ezkonekgal is offline Offline
Junior Poster in Training

queue question

 
0
  #1
Jan 21st, 2009
When you put an item on a queue, how do you show the items inside the queue? do you use peek method? the situation is a linked queue...
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 823
Reputation: verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough 
Solved Threads: 73
verruckt24's Avatar
verruckt24 verruckt24 is offline Offline
Practically a Posting Shark

Re: queue question

 
0
  #2
Jan 21st, 2009
When putting an item inside the queue why do you want to show the queue. Or is it some assignment requirement that on every addition of element to the queue you need to show the queue structure ?
If yes, then write some method that traverses the entire queue and shows the data stored ar every location of the list queue.
If not give us details.
Get up every morning and take a look at the Forbes' list of richest people. If your name doesn't appear.... GET TO WORK !!!
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 91
Reputation: ezkonekgal is an unknown quantity at this point 
Solved Threads: 1
ezkonekgal ezkonekgal is offline Offline
Junior Poster in Training

Re: queue question

 
0
  #3
Jan 21st, 2009
Originally Posted by verruckt24 View Post
Or is it some assignment requirement that on every addition of element to the queue you need to show the queue structure ?.
Yes!..

Originally Posted by verruckt24 View Post
If yes, then write some method that traverses the entire queue and shows the data stored ar every location of the list queue.
.
  1. public String toString(){
  2. String s = "[ ";
  3. if (front.info != null){
  4. s += "( " + peek().toString() + " )" + " ]";
  5. }else{
  6. s += "]";
  7. }
  8. return s;
  9. }

my prof. instructed me or siad to have an tostring method for that.. so i had the above. but it shows only the first element added to the queue.. what's wrong with it?
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 823
Reputation: verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough 
Solved Threads: 73
verruckt24's Avatar
verruckt24 verruckt24 is offline Offline
Practically a Posting Shark

Re: queue question

 
0
  #4
Jan 21st, 2009
You need to traverse the queue entirely for that, currently you are just showing the info of the first node.
Do something like this :
  1. public void showQueue(myQueue head){
  2. myQueue temp = head;
  3. while(temp != null){
  4. System.out.println(temp.data.toString()); // prints out data at this node.
  5. temp = temp.next; // next should be the link to the next node
  6. }
  7. }

Don't assume my code to be working, rather the opposite, just treat it as a pseudocode for the traversing and printing logic.
Last edited by verruckt24; Jan 21st, 2009 at 7:57 am.
Get up every morning and take a look at the Forbes' list of richest people. If your name doesn't appear.... GET TO WORK !!!
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 91
Reputation: ezkonekgal is an unknown quantity at this point 
Solved Threads: 1
ezkonekgal ezkonekgal is offline Offline
Junior Poster in Training

Re: queue question

 
0
  #5
Jan 21st, 2009
Thanks!..
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC