C++ implementation of K-nearest neighbours