Читайте также:
|
|
#pragma once
class Many {
friend Many &operator | (Many &x, Many &y) {
Many *tmp = new Many ();
List *a;
a = x.q;
while (a!= 0) {
tmp->add (a->ch);
a = a->ps;
}
a = y.q;
while (a!= 0) {
tmp->add (a->ch);
a = a->ps;
}
return *tmp;
};
friend Many &operator & (Many &x, Many &y) {
Many *tmp = new Many ();
List *a;
List *b;
a = x.q;
while (a!= 0) {
b = y.q;
while (b!= 0) {
if (a->ch == b->ch) tmp->add (a->ch);
b = b->ps;
}
a = a->ps;
}
return *tmp;
};
friend Many &operator - (Many &x, Many &y) {
Many *tmp = new Many ();
List *a;
List *b;
bool t = false;
a = x.q;
while (a!= NULL) {
b = y.q;
t = false;
while (b!= NULL) {
if (a->ch == b->ch) t = true;
b = b->ps;
}
if (!t) tmp->add (a->ch);
a = a->ps;
}
return *tmp;
};
private:
typedef struct st {
int ch;
struct st *ps;
} List;
List *p;
List *q;
List *m;
public:
Many () {
p = NULL;
q = NULL;
m = NULL;
};
Many &operator = (Many &x) {
List *a;
a = x.q;
while (a!= NULL) {
add (a->ch);
a = a->ps;
}
return *this;
};
void add (int val) {
m = q;
while (m!= NULL) {
if (m->ch == val) return;
m = m->ps;
}
q = new List;
q->ps = p;
p = q;
q->ch = val;
return;
};
void del (int val) {
List *n, *s;
m = q;
while (m!= NULL) {
if (m->ch == val) {
if (m == q) {
p = m->ps;
delete m;
q = p;
m =q;
}
else {
s = m->ps;
delete m;
n->ps = s;
m = n;
}
}
n = m;
m = m->ps;
}
return;
};
void print () {
cout << "Print" << endl;
m = q;
while (m!= NULL) {
cout << m->ch << endl;
m = m->ps;
}
return;
};
};
Дата добавления: 2015-07-16; просмотров: 44 | Нарушение авторских прав
<== предыдущая страница | | | следующая страница ==> |
Файл реализации класса | | | Описать класс, реализующий стек. |