Data Structures and Algorithms with Object-Oriented Design Patterns in Python
next up previous index

Finding the Position of an Item and Accessing by Position

The findPosition method of the OrderedListAsLinkedList class is used to determine the position of an item in an ordered list implemented as a linked list. Its result is an instance of the nested Cursor class. The findPosition method is defined in Program gif

   program9502
Program: OrderedListAsLinkedList class findPosition method

In addition to self, the findPosition method takes as its argument an object that is the target of the search. The search algorithm used by findPosition is identical to that of find, which is given in Program gif. Consequently, the running time is the same: tex2html_wrap_inline61009, where tex2html_wrap_inline61007 is the time required to match two objects, and tex2html_wrap_inline61037 is the number of items in the ordered list.


next up previous index

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