Added the Implementaiton for the Sorting Logic