How to write this algorithm in C++?

Printable View