[   ^ to index...   |   next -->   ]

CSE 143/AC : 6 July 2000


ADT Example: Vector

Conceptually, a vector is a list of elements which can be accessed by index.

class Item { public: Item(); bool equals(Item& other); bool lessThan(Item& other); private: // hidden }; class Vector { public: Vector(); bool isEmpty(); int length(); void insert(int position, Item item); Item delete(int position); Item get(int position); // Find the index of the given item; -1 if not found int indexOf(Item item); private: };

Exercises (solutions...)

  1. Define the private part of this Vector using a statically sized array.
  2. Implement the indexOf method, using only other public methods of Vector.
  3. What if Vector kept all its Items in sorted order? Implement indexOf for a sorted vector.

Last modified: Thu Jul 6 13:52:01 PDT 2000