{ T *ms;
int size;
public:
vector(): size(0),ms(NULL) {}
~vector(){delete [] ms;}
void inkrem(const T &t) // 1
{ T *tmp = ms;
ms=new T[size+1]; // ms −
if(tmp) memcpy(ms,tmp,sizeof(T)*size); // tmp -> ms
ms[size++]=t; //
if(tmp) delete [] tmp; //
}
void decrem(void) // 1
{ T *tmp = ms;
if(size>1) ms=new T[--size];
if(tmp)
{ memcpy(ms,tmp,sizeof(T)*size); //
//
delete [] tmp; //
}
}
T &operator[](int ind) //
{ // if(ind<0 || (ind>=size)) throw IndexOutOfRange; //
// IndexOutOfRange
return ms[ind];
}
};
int main()
{ vector <int> VectInt;
vector <double> VectDouble;
VectInt. inkrem(3);
VectInt. inkrem(26);
VectInt. inkrem(12); // int- 3
VectDouble. inkrem(1.2);
VectDouble. inkrem(.26);// double- 2
int a=VectInt[1]; // a = ms[1]
cout << a << endl;
int b=VectInt[4]; //
cout << b << endl; //
double d=VectDouble[0];
cout << d << endl;
VectInt[0]=1;
VectDouble[1]=2.41;
return 0;
}
vector 2 : increm , dekrem [] i- .
vector , new. , vector <int> VectInt, int. , -, .
VectInt.increm(3);
VectInt.increm(26);
VectInt.increm(12);
() (3, 26 12).
, :
template vector<int>;
vector<int>, .
- , :
#include <iostream >
using namespace std;
template <class T1,class T2>
T1 sm1(T1 aa,T2 bb) //
{ return (T1)(aa+bb); //
} //
template <class T1,class T2>