// // This file contains the C# code from Program 7.12 of // "Data Structures and Algorithms // with Object-Oriented Design Patterns in C#" // by Bruno R. Preiss. // // Copyright (c) 2001--2002 by Bruno R. Preiss, P.Eng. All rights reserved. // // http://www.brpreiss.com/books/opus6/programs/pgm07_12.txt // public class OrderedListAsLinkedList : AbstractSearchableContainer, OrderedList { protected LinkedList linkedList; public OrderedListAsLinkedList() { linkedList = new LinkedList(); } public override void Insert(ComparableObject obj) { linkedList.Append(obj); ++count; } public ComparableObject this[int offset] { get { if (offset < 0 || offset >= count) throw new IndexOutOfRangeException(); LinkedList.Element ptr = linkedList.Head; for (int i = 0; i < offset && ptr != null; ++i) ptr = ptr.Next; return (ComparableObject)ptr.Datum; } } // ... }