This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Queue question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Queue question" Watch "Queue question" New topic
Author

Queue question

Flo Powers
Ranch Hand

Joined: May 12, 2004
Posts: 57
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
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

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

Joined: May 12, 2004
Posts: 57
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Queue question
 
Similar Threads
can anyone please help me spot my errors?
Java ArrayQueues
A continuation of my previous post, if I may...
Convert Queue Dequeue to Link list format
Queue Algorithm Doubt