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

Append Method

 

The Append method, the definition of which is given in Program gif, adds a new LinkedList.Element at the tail-end of the list. The appended element becomes the new tail of the list.

   program3839
Program: LinkedList class Append method.

The Append method first allocates a new LinkedList.Element. Its datum field is initialized with the value to be appended, and the next field is set to null. If the list is initially empty, both head and tail refer to the new element. Otherwise, the new element is appended to the existing list, and the just tail pointer is updated.

The running time analysis of the Append method is essentially the same as for Prepend. I.e, the running time is O(1).


next up previous contents index

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