fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void ksort(int a[], int n, int k)
  5. { int i, j, t;
  6. for (i = 0; i < k; i++)
  7. { int min = i;
  8. for (j = i+1; j < n; j++)
  9. if (a[j] < a[min]) min = j;
  10. t = a[min];
  11. for (j = min; j > i; j--)
  12. a[j] = a[j-1];
  13. a[i] = t;
  14. }
  15. }
  16.  
  17. int main() {
  18. int a[] = {5, 3, 8, 1, 6, 2, 8, 3, 10};// your code goes here
  19. ksort(a, 9, 3);
  20. for (int i=0; i<9;i++)
  21. cout<< a[i] << " ";
  22. return 0;
  23. }
Success #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
1 2 3 5 8 6 8 3 10