Implementation not clear

I am unsuccessful in my atempt to implement the code in c++ using the approach taught. Can you please provide the code for this.

Reference Code

All 3 approaches