template
class Myvector
{
private:
T * first;
T * last;
T * end;
};
要实现的函数:
构造函数
析构函数
拷贝构造
拷贝赋值
at()
empty()
full()
front()
back()
size()
clear()
expand() 二倍扩容函数
push_back()
pop_back()
#include <iostream>
#include<vector>
#include<cstring>
using namespace std;
template <typename T>
class Myvector
{
private:
T * first;
T * last;
T * end;
public:
T data;
Myvector *next;
Myvector():next(nullptr){} //无参构造
Myvector(T a):data(a),next(nullptr){} //有参构造
~Myvector(){} //析构
Myvector(const Myvector &other):data(other.data){ //深拷贝
next=new T[other.data];
strcpy=(next,other.next);
cout<<""<<next<<endl;
}
Myvector & operator=(const Myvector &other) //拷贝赋值
{
if(this!=&other)
{
this->data=other.data;
cout<<this->data<<endl;
}
}
T &at(T pos) //at
{
if(pos<0||pos>=data)
cout<<"错误"<<endl;
T &a=next[pos];
}
T empty() //empty
{
if(sizeof (next)==0)
{
cout<<"空"<<endl;
return -1;
}
}
T full() //full
{
if(next->last==next->end)
{
cout<<"已满"<<endl;
return -1;
}
}
T front() //front
{
if(empty()==-1)
return -1;
else
return next->first;
}
T back() //back
{
if(empty()==-1)
return -1;
else
{
T e=sizeof (next);
return next->e;
}
}
T size() //size
{
return sizeof (next);
}
T clear() //clear
{
delete []next;
}
T expand() //expand二倍扩容
{
Myvector(data.next);
data.first==next->first;
data.last==next->end;
data.end==2*next->end;
}
T push_back(const T &val) //push_back()
{
T e=1+sizeof (next);
if(empty()==-1)
return -1;
else
next->e==&val;
}
T pop_back() //pop_back
{
T e=sizeof (next);
if(empty()==-1)
return -1;
else
delete []next->e;
}
};