-
Notifications
You must be signed in to change notification settings - Fork 1
/
setMath.h
95 lines (67 loc) · 1.54 KB
/
setMath.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#pragma once
// Functions as a mathamatical Set
// A Set is simply a collection of any objects.......
/*
Implementation
A set is simply a collection of objects
Simply a wrapper around a set
Usage
set<string> outcomes = {"head" , "tails"}
*/
#include <iterator>
#include <set>
#include <iostream>
#include <algorithm>
#include <initializer_list>
template <class T>
class setMath
{
public:
setMath() {};
setMath(std::initializer_list<T> list) : _set(list) {}
~setMath();
void insert(T elem);
int size();
void print();
setMath<T> getUnion(setMath<T> &rhs);
setMath<T> getIntersection(setMath<T> &rhs);
//setMath<T> beginElem();
//setMath<T> endElem();
private:
std::set<T> _set;
};
template <class T>
setMath<T>::~setMath() {}
template <class T>
void setMath<T>::insert(T elem)
{
_set.insert(elem);
}
template <class T>
int setMath<T>::size()
{
return _set.size();
}
template <class T>
setMath<T> setMath<T>::getUnion(setMath<T> &rhs)
{
setMath<T> result;
result._set.insert(_set.begin(), _set.end());
result._set.insert(rhs._set.begin(), rhs._set.end());
return result;
}
template <class T>
setMath<T> setMath<T>::getIntersection(setMath<T> &rhs)
{
setMath<T> result;
set_intersection(_set.begin(), _set.end(), rhs._set.begin(), rhs._set.end(), std::inserter(result._set , result._set.begin() ) );
return result;
}
template <class T>
void setMath<T>::print()
{
for (auto i : _set)
{
std::cout << i << std::endl;
}
}