(1)-(4)自己写吧。
(5)vector& operator= (const vector& v)
{
if(v.size != size)
{
free(data);
data = NULL;
size = v.size;
data = (int *)malloc(sizeof(int) * size);
if (!data)
{
size = 0;
return *this;
}
}
for(int i = 0; i < size; ++i)
{
data[i] = v.data[i];
}
return *this;
}
(6)friend std::ostream& operator<<(std::ostream& os, const vector &v)
{
for(int i = 0; i < v.size; ++i)
{
os << v.data[i] << " ";
}
os << std::flush;
return os;
}
照得字太小,看不清!