Sort:  

Thank you, @gaitan. I had read your post before I started to write this one. But here I tell people about the trick used in this algorithm behind the scene.

Great work! And I also know how it's done, now.