Originally posted by B pandoo:
i have a doubt.i coplied the program i got the ouput as
(space)Java
(space)java
$
usually queue will sort it,so i am getting the above 3 output.but
i want to know what happenened to the other two entries
(without space)java and (without space)Java.
please let me know.
Yes, it's a tricky one - not fair really.
q.poll() removes the element from the queue. So think about the value of q.size() as you execute the loop. How many times does the loop execute if the size is changing.
When you have that sorted out, fix the program so that you get all five elements.