Solution using modified insertion sort as better alternative to STL sort() function