If the array contains the numbers 1 to N, then you can just print the numbers 1 to N in the sort Order you want without looking at the array.