Google
 
Site navigation: [ Home | Theory | Java | Moodle courses | Resource wiki | About ]

Queues

HL Mastery aspects:

ADT queue

 

 

 

Example Queue Applet

SingtelQueue.java
CustomerNode.java
CustomerQueue.java

QueueFullException.java
QueueEmptyException.java

Whereas the stack is a LIFO (Last In First Out) structure, the queue is FIFO - First In First Out. Using a linked list we simply add (or enqueue ) items at the back and remove ( dequeue ) items from the front :

 

Exercise

Create a Queue Class that implements a character queue based upon the CharacterNode Class (see stacks page). The Queue should implement the methods enqueue and dequeue and throw an exception if the queue is empty.

Construct an Applet that demonstrates that your queue ADT works correctly.

Back to top

A deque

A deque (pronounced "deck") is a double-ended queue, elements may be enqueued and dequeued at either the front or the back.  So it can also be used as a double ended stack!

The deque can be used for such exotic tasks as keeping track of lists of undo and redo items in your word processor.

Example Queue Applet

Back to top

Related: [ Java home | Previous: stacks | Next: recursion ]

You can read more about queues in theory topic 5.


 
The site is partly financed by advertising revenue, partly by online teaching activities and partly by donations. If you or your organisation feel these resouces have been useful to you, please consider a donation, $9.95 is suggested. Please report any issues with the site, such as broken links, via the feedback page, thanks.

Questions or problems related to this web site should be addressed to Richard Jones who asserts his right to be identified as the author and owner of these materials - unless otherwise indicated. Please feel free to use the material presented here and to create links to it for non-commercial purposes; an acknowledgement of the source is required by the Creative Commons licence. Use of materials from this site is conditional upon your having read the additional terms of use on the about page and the Creative Commons Licence. View privacy policy.

Creative Commons License


This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License. © 2001 - 2009 Richard Jones, PO BOX 246, Cambridge, New Zealand;
This page was last modified: May 31, 2009