Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //---------------------------------------------------------------------------
- #pragma hdrstop
- #include <iostream.h>
- //---------------------------------------------------------------------------
- struct TPoint {
- int x, y;
- };
- struct TListItem {
- TPoint value;
- TListItem *Next;
- };
- class TSet {
- private:
- int listSize;
- int maxValue;
- TListItem *First, *Last;
- public:
- TSet() {
- listSize = 10;
- maxValue = 20;
- First = NULL;
- Last = NULL;
- }
- ~TSet() {
- destroySet();
- }
- void destroySet() {
- TListItem *t = First, *r;
- while (t != NULL) {
- r = t->Next;
- free(t);
- t = r;
- }
- First = NULL;
- Last = NULL;
- }
- void input() {
- srand(time(NULL));
- TPoint p;
- for(int i = 0; i < listSize; i++) {
- p.x = (rand() % maxValue) - maxValue/2;
- p.y = (rand() % maxValue) - maxValue/2;
- addItem(p);
- }
- }
- void addItem(TPoint p) {
- if(First == NULL) {
- First = (TListItem*) malloc(sizeof(TListItem));
- First->Next = NULL;
- First->value = p;
- Last = First;
- } else {
- Last->Next = (TListItem*) malloc(sizeof(TListItem));
- Last->Next->Next = NULL;
- Last->Next->value = p;
- Last = Last->Next;
- }
- }
- void output() {
- TListItem *t = First;
- while(t != NULL) {
- cout << "(" << t->value.x << ";" << t->value.y << ") ";
- t = t->Next;
- }
- cout << endl;
- }
- TSet& operator=(const TSet &ob) {
- destroySet();
- TListItem *t = ob.First;
- while(t != NULL) {
- addItem(t->value);
- t = t->Next;
- }
- return *this;
- }
- int static getNumber(){
- return 5;
- }
- };
- #pragma argsused
- int main(int argc, char* argv[])
- {
- TSet ob1, ob2;
- TPoint p;
- p.x = 1;
- p.y = 2;
- ob1.input();
- ob1.output();
- ob2 = ob1;
- ob2.addItem(p);
- ob1.output();
- ob2.output();
- cin.get();
- cin.get();
- return 0;
- }
- //---------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement