fork download
  1. def quicksort(lo, hi, vec):
  2.  
  3. i = lo
  4. j = hi
  5. pivot = vec[ (lo + hi) >> 1]
  6.  
  7. while i <= j:
  8. while vec[i] < pivot:
  9. i += 1
  10. while vec[j] > pivot:
  11. j -= 1
  12. if i <= j:
  13. aux = vec[i]^vec[j]
  14. vec[i] = aux ^ vec[i]
  15. vec[j] = aux ^ vec[j]
  16. i += 1
  17. j -= 1
  18. if lo < j:
  19. quicksort(lo, j, vec)
  20. if i < hi:
  21. quicksort(i, hi, vec)
  22.  
  23. def main():
  24. vec = [9,8,7,6,5,4,3,2,1,0]
  25.  
  26. N = len(vec)
  27.  
  28. for i in range(0, N):
  29. print(vec[i], end = ' ')
  30.  
  31. quicksort(0, N - 1, vec)
  32.  
  33. print()
  34.  
  35. for i in range(0, N):
  36. print(vec[i], end = ' ')
  37.  
  38. print()
  39. main()
  40. # your code goes here
Success #stdin #stdout 0.02s 8912KB
stdin
Standard input is empty
stdout
9 8 7 6 5 4 3 2 1 0 
0 1 2 3 4 5 6 7 8 9