Vector - #ifndef __VECTOR_H #define __VECTOR_H #include

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: #ifndef __VECTOR_H #define __VECTOR_H #include <stdexcept> using namespace std; // Deal with constants if they are not defined #ifndef INITIAL_CAPACITY #define INITIAL_CAPACITY 10 #endif #ifndef EXPANSION_FACTOR #define EXPANSION_FACTOR 2 #endif #ifndef EXPANSION_CONSTANT #define EXPANSION_CONSTANT 0 #endif template<typename ItemType> class Vector { private: /** The current capacity of the vector */ int currentCapacity; /** The current size of the vector */ int numItems; /** Array that contains the data */ ItemType *data; public: /** * Default constructur */ Vector<ItemType>() : currentCapacity(INITIAL_CAPACITY), numItems(0), data(new ItemType[INITIAL_CAPACITY]) { } /** * Copy constructor */ Vector<ItemType>(const Vector<ItemType>& other) : currentCapacity(other.currentCapacity), data(new ItemType[other.currentCapacity]), numItems(other.numItems) { for (int i=0; i<numItems; i++) data[i] =[i]; } /** * Destructor */ ~Vector<ItemType>() { delete data; } /** * Access the length */ int size() const { return numItems; } /**...
View Full Document

This note was uploaded on 05/03/2011 for the course CSCI 180 taught by Professor Goldwasser,m during the Fall '08 term at Saint Louis.

Page1 / 3

Vector - #ifndef __VECTOR_H #define __VECTOR_H #include

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

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