Data Structures and Algorithms
with Object-Oriented Design Patterns in C#![]() ![]() ![]() ![]() ![]() |
As shown in Program ,
objects that implement the Cursor interface
can be used to access, insert, and delete objects in an ordered list.
Program
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.
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 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).