Cover Data Structures and Algorithms with Object-Oriented Design Patterns in Java
next up previous contents 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 inner class MyCursor. The findPosition method is defined in Program gif

   program9523
Program: OrderedListAsLinkedList class findPosition method

The findPosition method takes as its argument a Comparable 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_inline60524, where tex2html_wrap_inline60522 is the time required to match two Comparable objects, and tex2html_wrap_inline60196 is the number of items in the ordered list.


next up previous contents index

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