Eventualmente puoi usare la funzione qsort della libreria standard.