Decrement Element and union of set
Hello
Plz help me. I can't Decrement Element and union of set.
assume the set 2 have element{1 , 2, 3, 4}
set2 = set2 - 3;
output is
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 75 76 77 78 79 80 81
|
#ifndef SET_H
#define SET_H
#include <iostream>
#include<list>
using namespace std;
class Set{
friend ostream& operator<<(ostream &, const Set &);
friend istream& operator>>(istream &, Set &);
private:
int *element; //element of set
int currentSize; //size
int maxSize; //max size
public:
Set(int = 0);
~Set();
int getSize() const;
int getSet(int) const;
void setNull();
void push(int);
Set operator-(int) const;
};
#endif
#include <iostream>
#include<list>
#include "set.h"
using namespace std;
Set:: Set(int s){
element = 0;
currentSize = 0;
maxSize = s;
if(s > 0){
element = new int[s];
}
}
Set:: ~Set(){
delete [] element;
}
int Set:: getSize() const{
return currentSize;
}
int Set:: getSet(int e) const{
return element[e];
}
void Set:: setNull(){
for(int i = 0; i < currentSize ; i++){
element[i] = 0;
}
currentSize = 0;
}
void Set::push(int e) {
element[currentSize] = e;
currentSize++;
}
Set Set:: operator-(int n) const{
int newMaxSize = maxSize - 1;
Set resultSet(newMaxSize);
for(int i = 0; i < getSize(); i++){
if(i != n){
resultSet.push(element[i]);
}
//resultSet.push(element[currentSize - n] = 0);
}
return resultSet;
}
};
#endif
|
and How I can implement union function?
help me please T^T
Last edited on
How I can implement union function? |
Create a new set.
Add all the elements from the first set to the new set.
Add all the elements from the second set to the new set.
return the new set.
Topic archived. No new replies allowed.