Skip to content

Instantly share code, notes, and snippets.

@petterroea
Created April 17, 2018 20:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petterroea/0e55e0d0e0d4aa1ecc66c567c5b96411 to your computer and use it in GitHub Desktop.
Save petterroea/0e55e0d0e0d4aa1ecc66c567c5b96411 to your computer and use it in GitHub Desktop.
simpleSet
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;
#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