Created
April 17, 2018 20:35
-
-
Save petterroea/0e55e0d0e0d4aa1ecc66c567c5b96411 to your computer and use it in GitHub Desktop.
simpleSet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SimpleSet<int> ss; | |
for(int i = 0; i <= 100; i++) { | |
ss.insert(i); | |
} | |
std::cout << "Simpleset made" << std::endl; | |
std::cout << ss << std::endl; | |
for(int a = 2; a < 50; a++) { | |
for(int b = a; b < 100; b++) { | |
if( b%a == 0 && b != a) { | |
ss.remove(b); | |
} | |
} | |
} | |
std::cout << "Simpleset primes" << std::endl; | |
std::cout << ss << std::endl; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
template<class T> | |
class SimpleSet{ | |
public: | |
/** Construct empty set **/ | |
SimpleSet(); | |
/** Destructor */ | |
~SimpleSet(); | |
/** Insert i into set, return true if the element was inserted, else false **/ | |
bool insert(T i); | |
/** Returns true if i is in the set **/ | |
bool exists(T i); | |
/** Removes i from the set, return true if an element was removed **/ | |
bool remove(T i); | |
friend std::ostream& operator<<(std::ostream& os, const SimpleSet<T>& ss); | |
private: | |
/** Dynamic array containing set elements **/ | |
T *data; | |
/** Current number of elements **/ | |
int currentSize; | |
/** Max capasity of data **/ | |
int maxSize; | |
/** Returns the index where i may be found, else an invalid index. **/ | |
int find(T i); | |
/** Resizes data, superflous elements are dropped. **/ | |
void resize(int n); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment