Handling Duplicates in Sorting Algorithms