This is an implementation of a data structure that supports adding new elements and calculating the median of the current set of elements
- The implementation of the data structure is located in
/include
and/src
/test
implements unit tests with the GoogleTest testing frameworkmain.cpp
implements a simple program that demonstrates the usage of the data structure. It reads N integers from the console and prints the current median after each new integer- The Median data structure is implemented as a static library, which is linked to the tests executable or the main executable, depending on the build target type
- add(int) - adds a new element to the set
Time complexity: O(lgN) where N is the number of elements that have already been added
- median() - returns the current median element. It is the arithmetic average of the two medians if the total number of elements is even
Time complexity: O(1)/constant
$ cmake -E make_directory ./build
$ cmake -S . -B ./build -DCMAKE_BUILD_TYPE={Debug/Release}
$ cmake --build ./build --config {Debug/Release}
$ ./build/median
$ cd ./build && ctest
- Use
setup_build.sh
to create the build directory and generate the build files - Use
run_tests.sh
to build and run the unit tests - Use
run_median.sh
to build and run the sample executable
Note that you need Git Bash or WSL to run the scripts on Windows