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

first and last Properties

Two more LinkedList properties are defined in Program gif. 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.

   program3893
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).


next up previous index

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