wingman007

AlgorithmsDataStructuresJavaSelectionSort

Oct 18th, 2025
1,205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.39 KB | Software | 0 0
  1. // сортиране чрез избор (Selection Sort)
  2. int[] array = {64, 25, 12, 22, 11};
  3. for (int i = 0; i < array.length - 1; i++) {
  4.     int minIndex = i;
  5.     for (int j = i + 1; j < array.length; j++) {
  6.         if (array[j] < array[minIndex]) {
  7.             minIndex = j;
  8.         }
  9.     }
  10.     int temp = array[minIndex];
  11.     array[minIndex] = array[i];
  12.     array[i] = temp;
  13. }
  14.  
Advertisement