Skip to content

Instantly share code, notes, and snippets.

@hrdavis
Created December 18, 2014 02:44
Show Gist options
  • Save hrdavis/28f3a4cf5525655c425e to your computer and use it in GitHub Desktop.
Save hrdavis/28f3a4cf5525655c425e to your computer and use it in GitHub Desktop.
package selectionsort;
public class SelectionSort
{
public static void Selection_Sort( int array[] )
{
int hold;
int index;
for ( int i = 0; i < array.length - 1; i++ )
{
// Let the first index be the least element
index = i;
for ( int j = i + 1; j < array.length; j++ )
{
// Test to see if the first element is the least element
if ( array[ j ] < array[ index ] )
{
// Save the index of the least element
index = j;
}
}
// Swap the current element at index i with the minimum element
hold = array[ i ];
array[ i ] = array[ index ];
array[ index ] = hold;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment