Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,25 @@
public class SelectionSort {

public void sort(int[] array) {

// the index of the minimum value
int minIndex = -1;

// perform the operation n-1 times
for(int k = 0; k < arr.length; k++) {
// initial minimum value
int min = Integer.MAX_VALUE;
//loop through the values of the unsorted partition
for(int i = k; i < arr.length; i++) {
min = Math.min(min, arr[i]);
//update the index of the minimum value in the array
if(min == arr[i]) {
minIndex = i;
}
}
//swap
int temp = arr[k];
arr[k] = arr[minIndex];
arr[minIndex] = temp;
}
}
}