#include <iostream>
using namespace std;
template <typename T>
class myvector{
private:
T *first;
T *last;
T *end;
public:
//有参
myvector():first(nullptr),last(nullptr),end(nullptr){}
//析构
~myvector(){}
//拷贝构造
myvector(const myvector & other){
int len=other.size();
first=new T [len];
last=first+len;
end=last; //初始化end=last
}
//拷贝赋值
myvector & operator = (const myvector & other){
if(this!=other){
int len =other.size();
first=new T[len];
last=first+len;
end=last;
}
return *this;
}
//判空
bool empty(){
return first == last;
}
//判满
bool full(){
return last==end;
}
//获取指定下标
T &at(int index){
return first[index];
}
//返回第一个元素
T & front(){
return *first;
}
//返回最后一个元素
T & tail(){
return *(last-1);
}
//返回容器大小 size
int size(){
return last-first;
}
//清理容器
void clear(){
return last=first;
}
//二倍扩容
void expand(){
int length = size();
int newvector = length*2; //扩容
T *newfirst = new T[newvector]; //创建空间
T *newlast = newfirst + length;
T *newend = newfirst + newvector;
for(int i=0;i<length;i++) //赋值
{
newfirst[i] = first[i];
}
delete []first; //释放
first = newfirst;
last = newlast;
}
//尾插
void push_back(const T &key){
*last=key;
last++;
if(last>end) end=last;
}
//尾删
void pop_back(){
last--;
}
};
int main()
{
myvector<int> m1;
//插入
for (int i = 0; i < 20; i++)
{
m1.push_back(6666);
}
//输出
for(int i=0;i<m1.size();i++)
{
cout<<m1.at(i)<<" ";
}
cout<<endl;
//删除
m1.pop_back();
for(int i=0;i<m1.size();i++)
{
cout<<m1.at(i)<<" ";
}
cout<<endl;
return 0;
}