fork download
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4. int T[20] = {68, 29, 99, 2, 25, 16, 15, 24, 52, 21,
  5. 12, 91, 67, 5, 57, 4, 51, 17, 79, 71};
  6.  
  7. int i, j, key;
  8.  
  9. // 基本挿入法(Insertion Sort)
  10. for (i = 1; i < 20; i++) {
  11. key = T[i];
  12. j = i - 1;
  13.  
  14. while (j >= 0 && T[j] > key) {
  15. T[j + 1] = T[j];
  16. j--;
  17. }
  18. T[j + 1] = key;
  19. }
  20.  
  21. // ソート結果の表示
  22. for (i = 0; i < 20; i++) {
  23. printf("%d", T[i]);
  24. if (i != 19) {
  25. printf(", ");
  26. }
  27. }
  28. printf("\n");
  29.  
  30. return 0;
  31. }
  32.  
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
2, 4, 5, 12, 15, 16, 17, 21, 24, 25, 29, 51, 52, 57, 67, 68, 71, 79, 91, 99