I write this,but it didn't work...
template<typename T>
typename vector<T>::iterator vector<T>::insert(iterator pos,const T& val)
{
int a=0,b=0;
if(capacity()==0) a=capacity()+1;
if(capacity()==size())
{
a=capacity()*2;
T *start2=operator new[](a*sizeof(T)))
for(int i=0;;i++)
{
new(start2+i) T(start+i);
if(start2+i==pos)
{
b=start2+i;
break;
}
}
start2+pos=val;
for(int j=b;j<=2*size();j++)
{
new(start2+j) T(start+j+1);
}
}
else if(capacity()>size())
{
for(int i=0;i<=capacity();i++)
{
if(start+i==pos)pos=
}
}
}
Use insert() or push_back() functions provided for std::vector
There is already an insert() function in std::vector.
精彩评论