example C++ code for kNN