classic algorithm using c++ to implement