Basic algorithms in c++