fork download
  1. /*
  2.   Copyright 2011 Marek "p2004a" Rusinowski
  3.   Insertion sort
  4. */
  5. #include <cstdio>
  6.  
  7. #define MAXN 1000000
  8.  
  9. int array[MAXN];
  10.  
  11. int main() {
  12. int n;
  13. scanf("%d", &n);
  14. for (int i = 0; i < n; ++i) {
  15. scanf("%d", &array[i]);
  16. }
  17. for (int i = 1; i < n; ++i) {
  18. for (int j = i; j > 0 && array[j] < array[j - 1]; --j) {
  19. int tmp = array[j];
  20. array[j] = array[j - 1];
  21. array[j - 1] = tmp;
  22. }
  23. }
  24. for (int i = 0; i < n; ++i) {
  25. printf("%d ", array[i]);
  26. }
  27. printf("\n");
  28. return 0;
  29. }
  30.  
stdin
10
10 9 8 7 6 5 4 3 2 1
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:13: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result
prog.cpp:15: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result
stdout
1 2 3 4 5 6 7 8 9 10