fork download
  1. /*
  2.   Copyright 2011 Marek "p2004a" Rusinowski
  3.   Quick sort
  4. */
  5. #include <cstdio>
  6.  
  7. #define MAXN 1000000
  8.  
  9. int array[MAXN];
  10.  
  11. void sort(int *begin, int *end) {
  12. if (begin + 1 >= end) return;
  13. int cur = *begin, *front = begin + 1, *back = end - 1;
  14. while (front <= back) {
  15. if (*back <= cur) {
  16. int tmp = *back;
  17. *back = *front;
  18. *front = tmp;
  19. } else {
  20. --back;
  21. }
  22. if (*front <= cur) {
  23. *(front - 1) = *front;
  24. ++front;
  25. }
  26. }
  27. *(front - 1) = cur;
  28. sort(begin, front - 1);
  29. sort(front, end);
  30. }
  31.  
  32. int main() {
  33. int n;
  34. scanf("%d", &n);
  35. for (int i = 0; i < n; ++i) {
  36. scanf("%d", &array[i]);
  37. }
  38. sort(array, array + n);
  39. for (int i = 0; i < n; ++i) {
  40. printf("%d ", array[i]);
  41. }
  42. printf("\n");
  43. return 0;
  44. }
  45.  
stdin
10
10 9 8 7 6 5 4 3 2 1
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:34: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result
prog.cpp:36: 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