|
Data Structures and Algorithms
with Object-Oriented Design Patterns in Python |
Two more LinkedList properties are defined in Program
.
The first property provides an accessor
that returns the first list element.
Similarly, the last property provides an accessor
that returns the last list element.
The code for both methods is almost identical.
In the event that the list is empty,
a ContainerEmpty
exception is raised.

Program: LinkedList class first and last properties.
We will assume that in a bug-free program, neither the first nor the last property accessors will be called for an empty list. In that case, the running time of each of these methods is constant. That is, T(n)=O(1).