draft of c++ algorithm