Data Structures and Algorithms with Object-Oriented Design Patterns in Python
next up previous index

dequeueTail and getTail Methods

Program gif defines the dequeueTail and getTail methods of the DequeAsArray class.

   program7801
Program: DequeAsArray class dequeueTail and getTail methods.

The getTail method that returns the object found at the tail of the deque, having first checked to see that the deque is not empty. If the deque is empty, it raises a ContainerEmpty exception. Under normal circumstances, we expect that the deque will not be empty. Therefore, the normal running time of this method is O(1).

The DequeueTail method removes an object from the tail of the deque and returns that object. First, it checks that the deque is not empty and throws an exception when it is. If the deque is not empty, the method sets aside the object at the tail in the local variable result; it decreases the _tail instance attribute by one modulo the length of the array; adjusts the _count accordingly; and returns result. All this can be done in a constant amount of time so the running time of DequeueTail is a constant.


next up previous index

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