#include using namespace std; /* TO DO Convert the below code using templates so that it works with any type and not just int */ class MyVector { public: int* ptr ; int capacity ; int noOfElements ; MyVector( int sizeP = 10 ) { ptr = new int[sizeP] ; capacity = sizeP ; noOfElements = 0 ; } void print() { for( int i1=0 ; i1 < noOfElements ; i1++ ) { cout << ptr[i1] << " " ; } cout << endl ; } ~MyVector() { delete[] ptr ; } void push_back( const int& obj1 ) { if ( noOfElements < capacity ) { ptr[ noOfElements ] = obj1 ; noOfElements++ ; } else { int* ptr1 = new int[ noOfElements*2 ] ; for( int i1=0 ; i1 < noOfElements ; i1++ ) { ptr1[i1] = ptr[i1] ; } // delete[] ptr ; ptr = ptr1 ; ptr[ noOfElements ] = obj1 ; noOfElements++ ; } } }; int main() { /* MyVector vectorObj ; vectorObj.push_back( 1 ) ; vectorObj.push_back( 2 ) ; vectorObj.print() ; */ MyVector vectorObj ; vectorObj.push_back( 1 ) ; vectorObj.push_back( 2 ) ; vectorObj.print() ; MyVector vectorObj1 ; vectorObj1.push_back( "one" ) ; vectorObj1.push_back( "two" ) ; vectorObj1.print() ; }