|
Data Structures and Algorithms
with Object-Oriented Design Patterns in Python |
Program
defines the length property of the Array class.
The fget accessor simply invokes the __len__ method
which returns the length of the array.
The fset accessor of the length property
calls the setLength method which provides the means
to change the size of an array at run time.
This method can be used both to increase and to decrease
the size of an array.

Program: Array class length property.
The running time of this algorithm depends only on the new array length.
Let n be the original size of the array
and let m be the new size of the array.
Consider the case where
.
The method first allocates
and initializes a new array of size m.
Next, it copies at most
elements from the old array
to the new array.
Therefore,
.