Data Structures and Algorithms with Object-Oriented Design Patterns in Python
next up previous 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.

   program3946
Program: LinkedList class append method.

The append method first allocates a new LinkedList.Element. Its _datum instance attribute is initialized with the value to be appended, and the _next instance attribute is set to None. 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 index

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