fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int* mm(int* b, int* e, int* r, int d)
  5. {return b>e ? r : mm(b+1,e,(d?*b>*r:*b<*r)?b:r,d);}
  6.  
  7. void sort(int* b, int* e)
  8. {
  9. if (b>=e) return;
  10. int* p = mm(b,e,b,0);
  11. if (*p<*b) {int t=*b; *b=*p; *p=t;}
  12. sort(b+1,e);
  13. }
  14. void task(int* b, int* e)
  15. {int *f = mm(b,e,b,0), *t = mm(b,e,b,1); if (f<t) sort(f,t);}
  16.  
  17. void show(int* b, int* e)
  18. {cout<<*b<<" "; if (b<e) show(b+1,e); else cout<<endl;}
  19.  
  20. #define ELEMENTS_COUNT 15
  21.  
  22. int main() {
  23. int a[ELEMENTS_COUNT] = {4,7,2,1,9,12,32,6,5,74,69,11,3,60,17};
  24. int* e = a + ELEMENTS_COUNT - 1;
  25. show(a,e);
  26. task(a,e);
  27. show(a,e);
  28. return 0;
  29. }
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
4 7 2 1 9 12 32 6 5 74 69 11 3 60 17 
4 7 2 1 5 6 9 12 32 74 69 11 3 60 17