fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #define XORSWAP(a, b) ((a)^=(b),(b)^=(a),(a)^=(b))
  5.  
  6. int partition(int v[], int left, int right){
  7. int i, j, p;
  8.  
  9. p = v[left];
  10. i = left;
  11. j = right + 1;
  12. while(i < j){
  13. while(v[i] < p) i++;
  14. while(v[j] > p) j--;
  15. XORSWAP(v[i], v[j]);
  16. }
  17. XORSWAP(v[i], v[j]);
  18. XORSWAP(v[left], v[j]);
  19. return j;
  20. }
  21.  
  22. void quicksort(int v[], int left, int right){
  23. if(left < right){
  24. int s = partition(v, left, right);
  25. quicksort(v, left, s - 1);
  26. quicksort(v, s + 1, right);
  27. }
  28. }
  29.  
  30. int main(){
  31. int i;
  32. int v[10] = {7, 3, 1, 2, 5, 10, 9, 7, 8, 6};
  33.  
  34. quicksort(v, 0, 9);
  35. for(i = 0; i < 10; i++)
  36. printf("%d ", v[i]);
  37.  
  38. scanf("%d", &i);
  39. }
Time limit exceeded #stdin #stdout 5s 2156KB
stdin
Standard input is empty
stdout
Standard output is empty