Advertisement
cgorrillaha

Untitled

Mar 1st, 2022
923
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.46 KB | None | 0 0
  1. void selectionSort(int arr[], int n)
  2. {
  3.     int i, j, min_idx;
  4.  
  5.     // One by one move boundary of unsorted subarray
  6.     for (i = 0; i < n-1; i++)
  7.     {
  8.         // Find the minimum element in unsorted array
  9.         min_idx = i;
  10.         for (j = i+1; j < n; j++)
  11.         if (arr[j] < arr[min_idx])
  12.             min_idx = j;
  13.  
  14.         // Swap the found minimum element with the first element
  15.         swap(&arr[min_idx], &arr[i]);
  16.     }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement