sorts :: selection sort
public class SelectionSort
{
public static void main (String[] args)
{
int a[] = {53, 43, 63, 93, 103, 83, 13, 33, 23, 3, 73};
// selection Sort
for (int i = 0 ; i < a.length ; i++)
{
// find the subscript of the smallest element in a[] at or after position i
int swapIndex = findSmall (a, i);
// swap current element with the smallest remaining
int temp = a [i]; // store current position to a temp
a [i] = a [swapIndex]; // smallest position index to current position
a [swapIndex] = temp; // current position to old smallest position index
}
// output sorted array
for (int i = 0 ; i < a.length ; i++)
{
System.out.print (a [i] + " ");
}
} // end of main
// find the subscript of the smallest element
public static int findSmall (int b[], int start)
{
int indexMin = start; // 'start' changes as 'i' changes
for (int i = start ; i < b.length ; i++)
{
if (b [i] < b [indexMin])
{
indexMin = i; // found a smallest value, record subscript
}
}
return indexMin; // return index of smallest value
} // end of findSmall
} // end of SelectionSort class