|
Data Structures and Algorithms
with Object-Oriented Design Patterns in Python |
The definitions of the QueueAsArray class __init__
and purge methods are given in Program
.
In addition to self,
the __init__ takes a single parameter, size,
which specifies the maximum number of items that can be stored in the queue.
The __init__ method initializes the instance attributes as follows:
The _array instance attribute is initialized to an array of length _size
and the _head and _tail instance attributes,
are initialized to represent the empty queue.
The total running time for the QueueAsArray
__init__ method is O(n), where
.
The purpose of the purge method is to remove all the contents
of a container.
In this case, the objects in the queue occupy contiguous
array positions between _head and _tail.
To empty the queue,
the purge method walks through the occupied array positions
assigning to each one the value None as it goes.
Clearly, the running time for the purge method is O(n),
where
.