-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatu165CSet.h
74 lines (73 loc) · 1.08 KB
/
matu165CSet.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <iostream>
using namespace std;
class Set{
int n;
int *pS;
public:
Set() : n(0), pS(NULL){}
Set(Set &s)
{
n= s.n;
if(0!= n){
pS= new int[n+1];
for (int i= 1; i<= n; ++i){
pS[i]= s.pS[i];
}
}
}
~Set()
{
if (pS){
delete []pS;
pS= NULL;
n= 0;
}
}
void ShowElement() const
{
int temp= 0;
for (int i= 1; i< n; ++i){
for (int j= i+1; j< n; ++j){
if (pS[i]> pS[j]){
temp= pS[i];
pS[i]= pS[j];
pS[j]= temp;
}
}
}
cout<<"{";
for (int i= 1; i< n; ++i){
cout<<pS[i]<<",";
}
if (IsEmpty()){
cout<<"}"<<endl;
}
else{
cout<<pS[n]<<"}"<<endl;
}
}
bool IsEmpty() const
{
return n? false : true;
}
int size()
{
return n;
}
bool IsElement(int e) const
{
for (int i= 1; i<= n; ++i){
if (pS[i]==e){
return true;
}
}
return false;
}
bool operator <=(const Set &s) const;
bool operator ==(const Set &s) const;
Set & operator +=(int e);
Set & operator -=(int e);
Set operator | (const Set &s) const;
Set operator & (const Set &s) const;
Set operator - (const Set &s) const;
};