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

Positions of Items in a List

As shown in Program gif, objects that implement the Cursor interface can be used to access, insert, and delete objects in an ordered list. Program gif defines private nested class called OrderedListAsArray.MyCursor that implements the Cursor interface. The idea is that instances of this class are used by the OrderedListAsArray class to represent the abstraction of a position in an ordered list.

   program8886
Program: OrderedListAsArray.MyCursor class.

The MyCursor class has two fields, list and offset. The list field refers to an OrderedListAsArray instance and the offset field records records an offset in that list's array of objects. A single constructor is provided which simply assigns a given values to the list and offset fields. Program gif also defines the Datum property of the MyCursor class. This property provides a get accessor that returns the item in the array at the position record in the offset field, provided that position is valid. The running time of the accessor is simply O(1).


next up previous contents index

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