fork download
  1. def quick_sort(arr, low, high):
  2. if low < high:
  3. pi = partition(arr, low, high)
  4. quick_sort(arr, low, pi - 1)
  5. quick_sort(arr, pi + 1, high)
  6.  
  7. def partition(arr, low, high):
  8. pivot = arr[high]
  9. i = low - 1
  10. for j in range(low, high):
  11. if arr[j] < pivot:
  12. i += 1
  13. arr[i], arr[j] = arr[j], arr[i]
  14. arr[i + 1], arr[high] = arr[high], arr[i + 1]
  15. return i + 1
  16.  
  17. lista = [3, 1, 4, 5, 2]
  18. quick_sort(lista, 0, len(lista) - 1)
  19. print("Lista ordenada:", lista)
  20.  
Success #stdin #stdout 0.02s 7144KB
stdin
Standard input is empty
stdout
('Lista ordenada:', [1, 2, 3, 4, 5])