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

__init__ and purge Methods

Program gif defines the QueueAsLinkedList __init__ and purge methods. In the case of the linked list implementation, it is not necessary to preallocate storage. The __init__ method simply initializes the _list object as an empty list. The running time of the __init__ method is O(1).

The purge method empties the queue by invoking the purge method provided by the LinkedList class and then sets the _count instance attribute to zero. Since a linked-list can be purged in constant time, the total running time for the purge method is O(1).


next up previous index

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