Select sort

From , 5 Years ago, written in C++, viewed 194 times.
URL https://pastebin.vip/view/f1981e4b
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3.  
  4. void select_sort(int a[], int n) {
  5.     for(int i=0; i < n-1; i++) {
  6.         int j = i;
  7.         int smallest = a[j];
  8.         for(int k=i; k < n; k++) {
  9.             if (a[k] < smallest) {
  10.                 j = k;
  11.                 smallest = a[k];
  12.             }
  13.         }
  14.         int t = a[i];
  15.         a[i] = a[j];
  16.         a[j] = t;
  17.     }
  18. }
  19.  
  20. int main() {
  21.     int a[6] = {12,9,3,7,14,11};
  22.     select_sort(a, 6);
  23.     for(int i=0; i < 6; i++) {
  24.         printf("%d ", a[i]);
  25.     }
  26.     printf("\n");
  27.     return 0;
  28. }
  29.  

Reply to "Select sort"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website