A rather basic set class in C++17, originally written for a school assignment. There are two separate implementations. One uses a static array, while the other relies on a vector container for optimized memory usage and ease-of-use. However, they are completely interchangeable, as they share member function signatures.
- Set creation / deletion.
- Add elements.
- Delete elements.
- Empty a set.
- Get the size.
- Check for an element.
- Check for a subset.
- Check for a proper subset.
- Complement of a set, given a universal set.
- Union of two sets.
- Arithmetic mean of a set.
- Sort elements of a set.
- Print out a set.
- Difference of two sets.
- Reverse difference of two sets.
- Symmetric difference of two sets.
- Intersection of two sets.
- Cartesian product of two sets.
- Mutable universal set.
Add SetArray.h
and SetArray.cpp
, or SetVector.h
and SetVector.cpp
to your codebase of choice. Make sure to include the right header file for your needs:
#include "SetArray.h"
#include "SetVector.h"
I have written two source files to try out the class: mainTests.cpp
and
mainTestsEspecific.cpp
. If you feel inclined to compile them, make sure to
comment / uncomment the following line at the top, to switch between implementations.
#define VECTOR
Feel free to use the provided makefile
or code/build.bat
(if you're on Windows). If you wish to compile it on your own, make sure to configure the compiler toolchain for C++17.
This repository is released under the MIT license. See LICENSE.md for more information.