• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with extracting from Queue

 
Remaan Rem
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 445
1
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Thanks Raj.
 
Rajkamal Pillai
Ranch Hand
Posts: 445
1
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glad to be of help ANYTIME
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic