#include #include //used here using namespace std; struct Point //create struct Point { int x, y; Point(int x=0, int y=0):x(x), y(y) {} void print() {cout<<"("<= 0 && index < size); return &data[index]; } PointVector& operator=(const PointVector& p) { if(this == &p) return *this; //not doing repeated work delete[] data; size = p.get_size(); capacity = p.get_capacity(); data = new Point[capacity]; memcpy(data, p.get_data(), get_size_all()); return *this; } friend PointVector operator+(const PointVector& a, const PointVector& b) { assert(a.get_size() == b.get_size()); //only two vectors of the same dimention can be added PointVector c(a); for(unsigned i=0;i 0); //delete &data[size-1]; size--; } Point& at(unsigned index) { assert(index >=0 && index < size); //remind of range return data[index]; } bool empty() {return (size <= 0) ? 1 : 0;} //'true' means indeed empty Point& front() { assert(size > 0); return data[0]; } Point& back() { assert(size > 0); return data[size-1]; } bool insert(unsigned pos, const Point& p) { //assert(pos >= 0 && pos < size); if(pos < 0 || pos >= size) return 0; if(size == capacity) { capacity *= 1.3; Point *_data=new Point[capacity]; memcpy(_data, data, get_size_all()); delete[] data; data = _data; } memcpy(&data[pos+1], &data[pos], (size - pos + 1) * sizeof(Point)); data[pos].x = p.x; data[pos].y = p.y; size++; return 1; } bool erase(unsigned pos) { //assert(pos >= 0 && pos < size); if(pos < 0 || pos >= size) return 0; //delete &data[pos]; memcpy(&data[pos], &data[pos+1], (size - pos - 1) * sizeof(Point)); size--; return 1; } }; int main() //test(as document's required, may not cover all functions by accident) { PointVector pv; if(pv.empty()) cout<<"empty point vector!"<