aspose file tools*
The moose likes Beginning Java and the fly likes Queue Algorithm Doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Queue Algorithm Doubt" Watch "Queue Algorithm Doubt" New topic
Author

Queue Algorithm Doubt

deeps sinha
Greenhorn

Joined: Apr 20, 2012
Posts: 26
hi,
I have doubt in understanding the Queue program in "Data Structure and Algorithms Made Easy in Java " by Narasimha Karumanchi on page 135. I have run the program and enqueued 3 numbers and I called deque more than 5 times and every time its dequeing and giving me the numbers already dequeued. Also it does not delete the numbers after dequeing.I have made few changes in the deQueue method by using class Integer instead if int. Please help. Please find the program below

Thanks.





Praveen Kumar M K
Ranch Hand

Joined: Jul 03, 2011
Posts: 256
Can you provide more specifics on what you gave as input. What was the queue capacity, the input values and the removal sequence.

Thanks,
Praveen.
deeps sinha
Greenhorn

Joined: Apr 20, 2012
Posts: 26
Hi Parveen,
Here is my main method.....


Praveen Kumar M K
Ranch Hand

Joined: Jul 03, 2011
Posts: 256
In the deque method why are you setting front = rear - 1 when there is only an element in the queue?
Praveen Kumar M K
Ranch Hand

Joined: Jul 03, 2011
Posts: 256
And you seem to be missing an extra check in your isEmpty method too.

Edit : Perhaps it would be easier for you to see where you are going wrong(or not) by doing some simple scratch work using pen and paper. I suggest you write down the current values of front, rear and array elements after each queue operation. This would help a lot!
deeps sinha
Greenhorn

Joined: Apr 20, 2012
Posts: 26
Thanks for your advice Parveen,I too have the same doubt(front = rear - 1), actually this code is from a book "Data Structure and Algorithms Made Easy in Java " by Narasimha Karumanchi. Because I donot have much time. Can you tell me where can I find similar code. I have googled but all the links show the builtin Queue Interface. Please also advice a good book for datastructure and algorithms in java.
Praveen Kumar M K
Ranch Hand

Joined: Jul 03, 2011
Posts: 256
You can look into Data Structures and Algorithms in Java by Robert Lafore. Good book to get the basic hang of things.
deeps sinha
Greenhorn

Joined: Apr 20, 2012
Posts: 26
Thanks Parveen.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Queue Algorithm Doubt