typical algorithm writen with c/c++