Data Structures and Algorithms
with Object-Oriented Design Patterns in C#![]() ![]() ![]() ![]() ![]() |
Two more LinkedList properties are defined in Program .
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.
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).