Advertisement
cgorrillaha

Untitled

Mar 2nd, 2022
1,235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.55 KB | None | 0 0
  1. int[] sort(int[] arr){
  2.  
  3.     int min, minIndex, temp;
  4.  
  5.     // 'start' is the point where 'unsorted' array begins
  6.     for(int start = 0; start < arr.length - 1; start++){
  7.  
  8.       // Finding the minimum
  9.       min = arr[start];
  10.       minIndex = start;
  11.       for(int i = start + 1; i < arr.length; i++){
  12.         if(arr[i] < min){
  13.           min = arr[i];
  14.           minIndex = i;
  15.         }
  16.       }
  17.  
  18.       // Swap the minimum with the first element
  19.       temp = min;
  20.       arr[minIndex] = arr[start];
  21.       arr[start] = temp;
  22.     }
  23.  
  24.     return arr;
  25.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement