This repo contains c++ implementation of data structure for finding median. The implementation is done with two heaps(max_heap & min_heap). The invariant is that on every insertion in the data structure the max_heap has one element more than the min_heap and the top of the max_heap is the median or that both heaps have the same number of elements and the median is the average of the top elements of the heaps. This implementation gives O(lgn) time complexity on insertion and O(1) time complexity on getting the median.
In order to use the project you will need C++ compiler and CMake version >= 3.5.
$ # clone the repo
$ cd median
$ mkdir build && cd build
$ cmake ..
$ make
After that you can run the tests.
$ make test
The data structure provides the following interface:
class MedianStructure
{
public:
MedianStructure& insert(const double);
double getMedian();
};
This program is provided under an MIT open source license, read the LICENSE file for details.