Thursday, November 7, 2019
Computer And Kids Essays - C, Data Types, Metaprogramming, Ur, Const
Computer And Kids Essays - C, Data Types, Metaprogramming, Ur, Const Computer And Kids #include*stdlib.h* #include*assert.h* #include*iostream.h* #include*apvector.h* template *class itemType* apvector*itemType*::apvector() :mySize(0), myList(0) } template *class itemType* apvector*itemType*::apvector(int size) : mySize(size), myList(new itemType[size]) } template *class itemType* apvector*itemType*::apvector(int size, const itemType & fillValue) : mySize(size), myList(new itemType[size]) int k; for(k = 0; k * size; k++) myList[k] = fillValue; } } template *class itemType* apvector*itemType*::apvector(const apvector*itemType* & vec) : mySize(vec.length()), myList(new itemType[mySize]) int k; for(k = 0; k * mySize; k++) myList[k] = vec.myList[k]; } } template *class itemType* apvector*itemType*::apvector() delete [] myList; } template *class itemType* const apvector*itemType* & apvector*itemType*::operator = (const apvector*itemType* & rhs) if(this != &rhs) delete [] myList; mySize = rhs.length(); myList = new itemType[mySize]; int k; for(k = 0; k * mySize; k++) myList[k] = rhs.myList[k]; } } return *this; } template *class itemType* int apvector*itemType*::length() const return mySize; } template *class itemType* itemType & apvector*itemType*::operator [] (int k) if(k * 0 || mySize *= k) cerr ** Illegal Vector index: ** k ** max index = ; cerr ** (mySize - 1) ** endl; abort(); } return myList[k]; } template *class itemType* const itemType & apvector*itemType*::operator [] (int k) const if (k * 0 || mySize *= k) cerr ** Illegal vector index ** k ** max index = ; cerr ** (mySize - 1) ** endl; abort(); } return myList[k]; } template *class itemType* void apvector*itemType*::resize(int newSize) int k; int numToCopy = newSize * mySize ? newSize : mySize; itemType * newList = new itemType[newSize]; for(k = 0; k * numToCopy; k++) newList[k] = myList[k]; } delete [] myList; mySize = newSize; myList = newList;
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.