Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Мимика Максим. Задание 03_12 #8979

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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 @@ -12,7 +12,27 @@ public static void main(String[] args) {
}

static void selectionSort(int[] arr) {
//todo напишите здесь свою корректную реализацию этого метода, вместо существующей
if (arr == null || arr.length == 0) return;
for (int i = 0; i < arr.length; i++) {
int currentMinIndex = findMinIndexFromIndex(arr, i);
swap(arr, i, currentMinIndex);
}
}

static int findMinIndexFromIndex(int[] arr, int index) {
int minValue = arr[index];
int minIndex = index;
for (int i = index; i < arr.length; i++)
if (arr[i] < minValue) {
minIndex = i;
minValue = arr[i];
}
return minIndex;
}

static void swap(int[] arr, int indexSwap1, int indexSwap2) {
int swapValue = arr[indexSwap1];
arr[indexSwap1] = arr[indexSwap2];
arr[indexSwap2] = swapValue;
}
}