#ifndef CONTTEMP_H #define CONTTEMP_H #define NULL 0 //**************************the following is the class delcaration*********************************// template class ContTemp { private: int capacity; int size; T* elemArray; void Extend(); bool isFull() const; public: ContTemp(); int getLength() const; void Add(const T& newElem); ~ContTemp(); //destructor //please implement the iterator inner class //************************declaration of the inner iterator class**************************** class Iterator { friend class ContTemp; private: T* curr_ptr; Iterator(T* ptr); public: Iterator(); //default constructor Iterator operator++(int); //post-increment of ++ T& operator*() const; bool operator==(const Iterator other) const; };//class Iterator //please implement begin and end Iterator Begin() const; Iterator End() const; }; //************************implementation of the inner class************************** template ContTemp::Iterator::Iterator() { curr_ptr = NULL; } template ContTemp::Iterator::Iterator(T* ptr) { curr_ptr = ptr; } template typename ContTemp::Iterator ContTemp::Iterator::operator++(int) { Iterator temp = *this; this->curr_ptr = curr_ptr++; return temp; } template T& ContTemp::Iterator::operator*() const { return (*curr_ptr); } template bool ContTemp::Iterator::operator==(const Iterator other) const { return curr_ptr == other.curr_ptr; } //************************implementation of Begin() and End()************************** template typename ContTemp::Iterator ContTemp::Begin() const { return Iterator(&elemArray[0]); } template typename ContTemp::Iterator ContTemp::End() const { return Iterator(&elemArray[size - 1]); } //*****************the following is the method implementation of container*******************************// template ContTemp::ContTemp() { size = 0; capacity = 5; elemArray = new T[capacity]; } template int ContTemp::getLength() const { return size; } template void ContTemp::Add(const T& newElem) { if (!isFull()) { elemArray[size] = newElem; size++; } else { Extend(); Add(newElem); } } template void ContTemp::Extend() { capacity = capacity * 2; T* temp = new T[capacity]; for (int i = 0; i < size; i++) temp[i] = elemArray[i]; delete[] elemArray; elemArray = temp; } template bool ContTemp::isFull() const { return (size == capacity); } template ContTemp::~ContTemp() { delete[] elemArray; //garbage collection } #endif