This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Problem with extracting from Queue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem with extracting from Queue " Watch "Problem with extracting from Queue " New topic
Author

Problem with extracting from Queue

Remaan Rem
Ranch Hand

Joined: Mar 04, 2010
Posts: 36


Hi Every one :

The task this time : to extract the similar word from the queue without changing the order of words
or creating any other field -

So : this is my code :






How ever it is not doing what it should do :
it does not remove the the string and does not give the words in order
What do you think ?
Remaan Rem
Ranch Hand

Joined: Mar 04, 2010
Posts: 36
While q is the main queue and t is another queue used to help moving the elements and then returning them back.

Remaan
Rajkamal Pillai
Ranch Hand

Joined: Mar 02, 2005
Posts: 443
    
    1

Hi,

Why not iterate through each element in the original queue and check if the value is equal to what you want to remove. If it is not then push the same on to a different Queue. After the end of all iterations you ought to have a different Queue instance which contains all values from the original Queue except for the one that has to be removed.

Cheers,
Raj.
Remaan Rem
Ranch Hand

Joined: Mar 04, 2010
Posts: 36

Thanks Raj.
Rajkamal Pillai
Ranch Hand

Joined: Mar 02, 2005
Posts: 443
    
    1

Glad to be of help ANYTIME
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38087
    
  22
Please use spaces not tabs for indenting.

Why are you using a Queue for what appears to be sorting? Unless you have a PriorityQueue, which supports sorting with Comparable<T> or a Comparator<T>, Queues are not designed for sorting.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with extracting from Queue
 
Similar Threads
How do i develop 10*10 table using loops
Implementing auto increment programitcally
Ternary Operator behavior in JAVA
Problems searching through a list
variable scope question/confusion