Data Structures and Algorithms with Object-Oriented Design Patterns in C#
next up previous contents index

First and Last Properties

Two more LinkedList properties are defined in Program gif. The First property provides a get accessor that returns the first list element. Similarly, the Last property provides a get accessor that returns the last list element. The code for both methods is almost identical. In the event that the list is empty, a ContainerEmptyException  exception  is thrown.

   program3791
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 contents index

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