Potresti usare un merge sort ricorsivo in cui controlli anche l'uguaglianza