fork(1) download
  1. #include <stdio.h>
  2.  
  3. void InsertionSort(int v[], int len){
  4. int key, i, j;
  5.  
  6. for(i = 1; i < len; i++){
  7. key = v[i];
  8. j = i - 1;
  9. while(j >= 0 && v[i] > key){
  10. v[j + 1] = v[j];
  11. j--;
  12. }
  13. v[j + 1] = key;
  14. }
  15. }
  16.  
  17. int main(){
  18. int i;
  19. int v[10] = {7, 3, 1, 5, 2, 6, 4, 8, 10, 9};
  20.  
  21. InsertionSort(v, 10);
  22.  
  23. for(i = 0; i < 10; i++)
  24. printf("%d ", v[i]);
  25.  
  26. scanf("%d", &i);
  27. }
Success #stdin #stdout 0s 2164KB
stdin
Standard input is empty
stdout
7 3 1 5 2 6 4 8 10 9