Cover Data Structures and Algorithms with Object-Oriented Design Patterns in Java
next up previous contents index

The ``Head'' Methods

Program gif defines the methods enqueueHead and dequeueHead. The latter is trivial to implement--it simply calls the dequeue method inherited from the QueueAsLinkedList class.

The enqueueHead method takes a single argument--the object to be added to the head of the deque. The method simply calls the LinkedList.prepend method. Since the running time for prepend is O(1), the running time of enqueueHead is also O(1).


next up previous contents index

Bruno Copyright © 1998 by Bruno R. Preiss, P.Eng. All rights reserved.