fork download
  1. def _qs(lo, hi, arr):
  2.  
  3. i = lo
  4. j = hi
  5. middle = arr[(lo + hi)>>1]
  6.  
  7. while i <= j:
  8.  
  9. while arr[i] < middle:
  10. i += 1
  11. while arr[j] > middle:
  12. j -= 1
  13.  
  14. if i <= j:
  15. arr[i], arr[j] = arr[j], arr[i]
  16. i += 1
  17. j -= 1
  18.  
  19. if lo < j:
  20. _qs(lo, j, arr)
  21. if i < hi:
  22. _qs(i, hi, arr)
  23.  
  24. def qs(arr):
  25.  
  26. _qs(0, len(arr) - 1, arr)
  27.  
  28. def func():
  29.  
  30. arr = [4,54,7,8,9,10,-1]
  31.  
  32. print(arr)
  33.  
  34. qs( arr )
  35.  
  36. print( arr )
  37.  
  38. func()
Success #stdin #stdout 0.03s 9468KB
stdin
Standard input is empty
stdout
[4, 54, 7, 8, 9, 10, -1]
[-1, 4, 7, 8, 9, 10, 54]