K-NN algorithm C++ implementation