how to perform a selection sort java code example
Example: selection sort in java
public static void SelectionSort(int[] arr)
{
int small;
for (int i = 0; i <arr.length - 1; i++)
{
small = i;
for (int j = i + 1; j < arr.length; j++)
{
//if current position is less than previous smallest
if (arr[j] < arr[small])
{
small = j;
//swap values
int temp = arr[i];
arr[i] = arr[small];
arr[small] = temp;
}
}
}
}