Advertisement
Domy131097

Untitled

Jun 13th, 2019
114
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public void selectionSort(int[] arr){
  2.     for (int i = 0; i < arr.length - 1; i++) {
  3.         int index = i;
  4.         for (int j = i + 1; j < arr.length; j++) {
  5.             if (arr[j] < arr[index]) {
  6.                 index = j;
  7.             }
  8.         }
  9.         swap(arr[index], arr[i]);
  10.     }
  11. }
  12.  
  13. private void swap(int num1, int num2) {
  14.     int temp = num1;
  15.     num1 = num2;
  16.     num2 = temp;
  17. }
Advertisement
RAW Paste Data Copied
Advertisement