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: // some stuff }; const int MAX_VECTOR_SIZE = 40; 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; // return -1 if not in vector int indexOf(Item item); private: Item contents[MAX_VECTOR_SIZE]; int size; }; Exercises (solutions...)
- What should the constructor of this class do?
- Implement the indexOf method, using only other public methods of Vector (do not access the private members).
- What if Vector kept all its Items in sorted order? Implement indexOf for a sorted vector.