PointArray

Kolorwanie:
Status:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
/***********POINT*ARRAY*********/

class PointArray{
    Point *points;
    int array_size;

  public:
    PointArray();
    PointArray(const Point pts[], const int size);
    ~PointArray();

    void resize(int size);
    void push_back(const Point &p);
    int getSize() const {return array_size;}
    Point *get(const int position);
};

/***************POINT*ARRAY****************/

PointArray::PointArray()
{
    array_size = 0;
    points = new Point[0];
}

PointArray::PointArray(const Point pts[], const int size)
{
    array_size = size;
    points = new Point[size];

    for(int i=0; i<size; i++){
        points[i] = pts[i];
    }
}

PointArray::~PointArray()
{
    delete [] points;
    array_size = 0;
}

void PointArray::resize(int new_size)
{
    Point *new_points = new Point [new_size];
    int n = (array_size<new_size ? array_size:new_size);

    for(int i=0; i<n; i++){
        new_points[i] = points[i];
    }

    delete [] points;

    points = new_points;
    array_size = new_size;

}

void PointArray::push_back(const Point &p)
{
    resize(array_size+1);
    points[array_size] = p;
}

Point *PointArray::get(const int position)
{
    return (position >= 0) && (position < array_size) ? points + position :NULL;
}



Copyrights 2014-2019 © Wklejaj.pl Wszelkie prawa zastrzeżone.