I need the algo which i should follow.
After that i'd be able to see whether i can convert it to c++ or not.
I found an algo thru google but it wasn't correct