Skip to content

Commit c9f256e

Browse files
authored
Laboratory work 4
1 parent f7e1b7a commit c9f256e

File tree

5 files changed

+62
-8
lines changed

5 files changed

+62
-8
lines changed

Set_Cont_List_Kudashov/SetLab4_Kudashov.cpp

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ bool SetListContainer::checkingOfExistence(int checking_value) {
1717
}
1818
// Добавление нового элемента в множество в начало списка
1919
void SetListContainer::add(int adding_value) {
20-
set.push_front(adding_value);
20+
if (!checkingOfExistence(adding_value))
21+
set.push_front(adding_value);
2122
}
2223
// Мощность множества
2324
int SetListContainer::powerOfTheSet() {
@@ -70,11 +71,11 @@ bool SetListContainer::isEqual(SetListContainer a, SetListContainer b) {
7071
SetListContainer SetListContainer::combiningSets(SetListContainer a, SetListContainer b) {
7172
if (a.emptySet() || b.emptySet())
7273
return *new SetListContainer();
73-
a.set.sort();
74-
b.set.sort();
75-
a.set.merge(b.set);
76-
a.set.unique();
77-
return a;
74+
SetListContainer c = a;
75+
for (int iter: b.set)
76+
if(!c.checkingOfExistence(iter))
77+
c.add(iter);
78+
return c;
7879
}
7980
// Пересечение множеств
8081
SetListContainer SetListContainer::intersectionOfSets(SetListContainer a, SetListContainer b) {
@@ -99,3 +100,44 @@ SetListContainer SetListContainer::symmetricDifferenceOfSets(const SetListContai
99100
if (intersectionOfSets(a,b).emptySet()) return combiningSets(a,b);
100101
return differenceOfSets(combiningSets(a,b), intersectionOfSets(a,b));
101102
}
103+
/*
104+
// Проверка множеств на равенство
105+
bool SetListContainer::isEqual(SetListContainer a, SetListContainer b) {
106+
return a.set == b.set;
107+
}
108+
// Объединение множеств
109+
SetListContainer SetListContainer::combiningSets(SetListContainer a, SetListContainer b) {
110+
if (a.emptySet() || b.emptySet())
111+
return *new SetListContainer();
112+
a.set.sort();
113+
b.set.sort();
114+
a.set.merge(b.set);
115+
a.set.unique();
116+
return a;
117+
}
118+
// Пересечение множеств
119+
SetListContainer SetListContainer::intersectionOfSets(SetListContainer a, SetListContainer b) {
120+
if (a.emptySet() || b.emptySet())
121+
return *new SetListContainer();
122+
a.set.sort();
123+
b.set.sort();
124+
SetListContainer c = *new SetListContainer();
125+
set_intersection(a.set.begin(), a.set.end(), b.set.begin(), b.set.end(), inserter(c.set,c.set.begin()));
126+
return c;
127+
}
128+
// Разность множеств
129+
SetListContainer SetListContainer::differenceOfSets(SetListContainer a, SetListContainer b) {
130+
SetListContainer c = *new SetListContainer();
131+
a.set.sort();
132+
b.set.sort();
133+
set_difference(a.set.begin(), a.set.end(), b.set.begin(), b.set.end(), inserter(c.set,c.set.begin()));
134+
return c;
135+
}
136+
// Симметричная разность множеств
137+
SetListContainer SetListContainer::symmetricDifferenceOfSets(SetListContainer a, SetListContainer b) {
138+
SetListContainer c = *new SetListContainer();
139+
a.set.sort();
140+
b.set.sort();
141+
set_symmetric_difference(a.set.begin(), a.set.end(), b.set.begin(), b.set.end(), inserter(c.set,c.set.begin()));
142+
return c;
143+
}*/

Set_Cont_List_Kudashov/SetLab4_Kudashov.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,17 @@ class SetListContainer {
3434
static SetListContainer differenceOfSets(const SetListContainer& a, SetListContainer b);
3535
// Симметричная разность множеств
3636
static SetListContainer symmetricDifferenceOfSets(const SetListContainer& a, const SetListContainer& b);
37+
/*
38+
// Проверка множеств на равенство
39+
static bool isEqual(SetListContainer a, SetListContainer b);
40+
// Объединение множеств
41+
static SetListContainer combiningSets(SetListContainer a, SetListContainer b);
42+
// Пересечение множеств
43+
static SetListContainer intersectionOfSets(SetListContainer a, SetListContainer b);
44+
// Разность множеств
45+
static SetListContainer differenceOfSets(SetListContainer a, SetListContainer b);
46+
// Симметричная разность множеств
47+
static SetListContainer symmetricDifferenceOfSets(SetListContainer a, SetListContainer b);
48+
*/
3749
};
3850
#endif //SET_CONT_LIST_KUDASHOV_SETLAB4_KUDASHOV_H
Binary file not shown.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
Start testing: Feb 25 11:08 RTZ 2 (ceia)
1+
Start testing: Feb 25 15:21 RTZ 2 (ceia)
22
----------------------------------------------------------
3-
End testing: Feb 25 11:08 RTZ 2 (ceia)
3+
End testing: Feb 25 15:21 RTZ 2 (ceia)

0 commit comments

Comments
 (0)