Some basic algorithm in c++