Vector - The Vector Class A SIMPLE VECTOR CLASS file name...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
/**** The Vector Class *****/ /***** A SIMPLE VECTOR CLASS ****/ // file name: Vector.h #ifndef __VECTOR__ #define __VECTOR__ #include <cassert> using namespace std; template <class T> class Vector { public: Vector(int capacity = 10); // default constructor Vector( const Vector &); // copy constructor const Vector& operator=(const Vector &); // operator= ~Vector(); // destructor bool IsEmpty() const; int NumberOfItems() const; void AddLast(const T&); void RemoveLast(); const T& ShowLast() const; T& operator[](int); const T& operator[](int) const; void Resize(int); void RemoveAll(); private: T *array; int number_of_items; int size; }; // end of class Vector declaration /*** VECTOR CLASS MEMBER FUNCTIONS IMPLEMENTATION ***/ template <class T> Vector<T>::Vector(int capacity) { assert (capacity > 0); array = new T[capacity]; size = capacity; number_of_items = 0; } template <class T> Vector<T>::Vector(const Vector<T> &ob) {
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
array = new T[ob.size]; for (int i = 0; i < ob.number_of_items; i++)
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/07/2008 for the course CS 181 taught by Professor Satya during the Fall '08 term at Stevens.

Page1 / 3

Vector - The Vector Class A SIMPLE VECTOR CLASS file name...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online