small refactoring for better code readability (#247)
This commit is contained in:
@@ -3,15 +3,13 @@ import java.util.Arrays;
|
|||||||
public class SelectionSort2 {
|
public class SelectionSort2 {
|
||||||
|
|
||||||
// this version uses raw arrays instead of ArrayList
|
// this version uses raw arrays instead of ArrayList
|
||||||
public static void selectionSort(int[] target) {
|
public static void selectionSort(int[] arr) {
|
||||||
for (int i = 0; i < target.length - 1; i++) {
|
for (int i = 0; i < arr.length-1; i++) {
|
||||||
int left = target[i];
|
for (int j = i+1; j < arr.length; j++) {
|
||||||
for (int j = i + 1; j < target.length; j++) {
|
if (arr[j] < arr[i]) {
|
||||||
int right = target[j];
|
int temp = arr[i];
|
||||||
if (left > right) {
|
arr[i] = arr[j];
|
||||||
target[i] = right;
|
arr[j] = temp;
|
||||||
target[j] = left;
|
|
||||||
left = right;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user