as you have done it in c++ language and i only know c language so i cant understand that solution.so if you will do the solution of that problem iin c language then i will be able to understand that.