|
|
||
| You are here: | ||
|
HL Mastery aspects: ADT queue
Example Queue Applet |
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. 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
Related: [ Java home | Previous: stacks | Next: recursion ] |
You can read more about queues in theory topic 5. |
|
|
|||
|
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. 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 |