@@ -22,7 +22,7 @@ Node* add(Node*& first, int adding_value) {
2222 if (!checkingOfExistence (first, adding_value)){
2323 Node* new_node = new Node;
2424 new_node->value = adding_value;
25- new_node->next = emptySet (first) ? nullptr : first;
25+ new_node->next = first;
2626 first = new_node;
2727 }
2828 return first;
@@ -42,7 +42,7 @@ int powerOfTheSet (Node* first) {
4242// Создание нового множества
4343Node* creatingSet (int quantity, int min, int max, int k){
4444 Node* set = creatingAnEmptySet ();
45- // int k = 5; // коэффициент кратности
45+ // k - коэффициент кратности
4646 // Множество А – множество чисел, кратных 5. Множество В – множество чисел, кратных 10.
4747 if (k*quantity <= max - min + 1 ){
4848 while (powerOfTheSet (set) < quantity){
@@ -79,4 +79,69 @@ Node* deleteSet(Node*& first){
7979 }
8080 first = nullptr ;
8181 return first;
82+ }
83+ // Является ли A подмножеством B
84+ bool isSubset (Node* A, Node* B){
85+ if (emptySet (A)) return true ;
86+ if (powerOfTheSet (A) > powerOfTheSet (B)) return false ;
87+ Node* current = A;
88+ while (current->next ){
89+ if (!checkingOfExistence (B, current->value ))
90+ return false ;
91+ current = current->next ;
92+ }
93+ return true ;
94+ }
95+ // Проверка множеств на равенство
96+ bool isEqual (Node* A, Node* B){
97+ return isSubset (A,B) && (powerOfTheSet (A) == powerOfTheSet (B));
98+ }
99+ // Объединение множеств
100+ Node* combiningSets (Node* A, Node* B){
101+ if (emptySet (A) || emptySet (B))
102+ return creatingAnEmptySet ();;
103+ Node* C = A;
104+ Node* current = B;
105+ while (current->next ) {
106+ if (!checkingOfExistence (C, current->value ))
107+ C = add (C, current->value );
108+ current = current->next ;
109+ }
110+ if (checkingOfExistence (B, current->value ))
111+ C = add (C, current->value );
112+ return C;
113+ }
114+ // Пересечение множеств
115+ Node* intersectionOfSets (Node* A, Node* B){
116+ if (emptySet (A) || emptySet (B))
117+ return creatingAnEmptySet ();;
118+ Node* C = creatingAnEmptySet ();
119+ Node* current = A;
120+ while (current->next ){
121+ if (checkingOfExistence (B, current->value ))
122+ C = add (C, current->value );
123+ current = current->next ;
124+ }
125+ if (checkingOfExistence (B, current->value ))
126+ C = add (C, current->value );
127+ return C;
128+ }
129+ // Разность множеств
130+ Node* differenceOfSets (Node* A, Node* B){
131+ if (emptySet (A) || emptySet (B))
132+ return creatingAnEmptySet ();
133+ Node* C = creatingAnEmptySet ();
134+ Node* current = A;
135+ while (current->next ){
136+ if (!checkingOfExistence (B, current->value ))
137+ C = add (C, current->value );
138+ current = current->next ;
139+ }
140+ if (!checkingOfExistence (B, current->value ))
141+ C = add (C, current->value );
142+ return C;
143+ }
144+ // Симметричная разность множеств
145+ Node* symmetricDifferenceOfSets (Node* A, Node* B){
146+ return differenceOfSets (combiningSets (A,B), intersectionOfSets (A,B));
82147}
0 commit comments