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...)
- Define the private part of this Vector using a statically sized array.
- Implement the indexOf method, using only other public methods of Vector.
- What if Vector kept all its Items in sorted order? Implement indexOf for a sorted vector.