• 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 question

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I have a question about a queue class (I found this in Data Structures DeMYSTiFieD by Jim Keogh and Kend Davidson). It seems to me that when you enqueue the first element in a queue object created from this class, the first element in the array will be blank. Have I misunderstood the code or is it not utilizing the whole of the array?

Here is the code:



Thanks,
Flo
 
Ranch Hand
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are correct. In this implementation, the zero index array element is not being utilized. Thus a queue created with a initial size of 3, only holds two items.
 
Flo Powers
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Phew, I'm glad to hear I'd understood. Thanks!

Is this way of calculating the front and back of the queue (using modulo arithmetic) a fairly common implementation of a static queue? Also, are there other useful methods that you would normally expect to see in a queue class? I'm guessing the book has presented a rather barebones version in order not to obscure the essential characteristics of queues...

I realize that it might be preferable to use a linked list, though - would just like to make sure I've understood this properly.

Thanks,
flo
[ January 18, 2005: Message edited by: Flo Powers ]
 
That new kid is a freak. Show him this tiny ad:
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