• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Queue Algorithm Doubt

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.





 
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Parveen,
Here is my main method.....


 
Praveen Kumar M K
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 256
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 256
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Parveen.
 
In the renaissance, how big were the dinosaurs? Did you have tiny ads?
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic