/* Vector Template written by Jared Bruni www.LostSideDead.com "Open Source, Open Mind" */ template class Vector { public: Vector(); Vector(int size); ~Vector(); type operator[](int pos); void Resize(int size); void Add(type t); void Asn(int pos, type t); type Get(int pos); unsigned long Length(); private: type* array; unsigned long size; int i; }; template Vector::Vector() { array = 0; size = 0; } template Vector::Vector(int sizex) { size = sizex; array = new type[ size ]; } template Vector::~Vector() { if( array != 0 ) { delete [] array; array = 0; } } template type Vector::operator [](int pos) { if( pos > size || pos < 0 && array != 0 ) { return 0; } return array[pos]; } template void Vector::Resize(int sizex) { type* temp = new type[ size ]; for(i = 0; i < size; i++) { temp[i] = array[i]; } if(array != 0) { delete [] array; array = 0; } array = new type [ sizex ]; for(i = 0; i < size; i++) { if(i < sizex) { array[i] = temp[i]; } } delete [] temp; temp = 0; size = sizex; } template void Vector::Add(type t) { int size2; size2 = size + 1; Resize(size2); array[size2-1] = t; } template unsigned long Vector::Length() { return size; } template void Vector::Asn(int pos, type t) { if(pos < size && pos >= 0) { array[pos] = t; } } template type Vector::Get(int pos) { return this[pos]; }