#include<stdlib.h>
#include<time.h>
#include<string.h>
template<typename T> class vector {
private:
int max_size;
T *arr;
void resize() {
T *na=new T[2*max_size];
memcpy(na,arr,max_size*sizeof(T));
delete[] arr;
max_size*=2; arr=na;
}
public:
int size;
vector():max_size(2),size(0),arr(new T[2]) {}
~vector() {}
void push_back(const T val) {
if(size==max_size) resize();
arr[size++]=val;
}
void pop_back() {size--;}
T operator[](const int pos)const {
return arr[pos];
}
};
int main() {
srand(time(0));
vector<int>v;
for(register int i=1;i<=1e7;i++) v.push_back(rand());
}
模板:vector
最新推荐文章于 2023-12-14 15:08:40 发布