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

Removing Arbitrary Items by Position

The final method to be considered is the Withdraw method of the OrderedListAsLinkedList.MyCursor class. This method removes an arbitrary item from an ordered list, where the position of that item is specified by a cursor instance. The code for the Withdraw method is given in Program gif.

   program9660
Program: OrderedListAsLinkedList.MyCursor class Withdraw method.

The item in the linked list at the position specified by the cursor is removed by calling the Extract method provided by the LinkedList class. The running time of the Withdraw method depends on the running time of the Extract of the LinkedList class. The latter was shown to be O(n) where n is the number of items in the linked list. Consequently, the total running time is O(n).


next up previous contents index

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