Code Fragment: vector1



template <typename Object>
class ArrayVector {
private:
  int           capacity;			// length of array
  int           sz;				// number of elements in vector
  Object*	a;				// array storing the elements
protected:
  void overflow();				// handle overflow by resizing
public:
  ArrayVector(int initCap = 16) {		// constructor
    capacity    = initCap;
    sz          = 0;
    a           = new Object[capacity];
  }
  int size() const  				// number of elements
    { return sz; }
  bool isEmpty() const  			// is vector empty?
    { return size() == 0; }
  Object& elemAtRank(int r)  			// access element at rank r
    { return a[r]; }
  void replaceAtRank(int r, const Object& e)  	// replace element at given rank
    { a[r] = e; }
  void removeAtRank(int r);			// remove element at given rank
  void insertAtRank(int r, const Object& e);	// insert element at given rank
  // ... (housekeeping functions omitted)
};