Created
December 18, 2014 02:44
-
-
Save hrdavis/28f3a4cf5525655c425e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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