There may be other bugs, but one that sticks out is that selectionSort
doesn't actually do anything to the array. You pass in an array reference as the a
parameter:
private static void selectionSort(int[] a, int beginning, int end)
Since this is a reference, if selectionSort
did anything to assign to any elements of a
, like
a[x] = y;
it would change the element of the caller's array, like you want. But there is no statement in selectionSort
that changes anything in a
. The code copies elements to temp
, works with temp
--but then throws all the work away.