1
czheo OP ``` python
def quick_sort(numbers,left,right): if right - left <= 0: return numbers tmp = numbers[left] i = left + 1 j = right while i < j: while numbers[j] > tmp and i < j: j -= 1 while numbers[i] <= tmp and i < j: i += 1 numbers[i], numbers[j] = numbers[j], numbers[i] if numbers[i] > numbers[left]: numbers[i-1], numbers[left] = numbers[left], numbers[i-1] else: numbers[i], numbers[left] = numbers[left], numbers[i] quick_sort(numbers,left,i-1) quick_sort(numbers,i+1,right) return numbers test = [3,7,8,5,1,2,2,2,22,11,5,4] print(quick_sort(test, 0, len(test) - 1)) ``` |
2
czheo OP ```
def quick_sort(numbers,left,right): if right - left <= 0: return numbers tmp = numbers[left] i = left + 1 j = right while i < j: while numbers[j] > tmp and i < j: j -= 1 while numbers[i] <= tmp and i < j: i += 1 numbers[i], numbers[j] = numbers[j], numbers[i] if numbers[i] > numbers[left]: numbers[i-1], numbers[left] = numbers[left], numbers[i-1] else: numbers[i], numbers[left] = numbers[left], numbers[i] quick_sort(numbers,left,i-1) quick_sort(numbers,i+1,right) return numbers test = [3,7,8,5,1,2,2,2,22,11,5,4] print(quick_sort(test, 0, len(test) - 1)) ``` |
3
czheo OP ~~~
def quick_sort(numbers,left,right): if right - left <= 0: return numbers tmp = numbers[left] i = left + 1 j = right while i < j: while numbers[j] > tmp and i < j: j -= 1 while numbers[i] <= tmp and i < j: i += 1 numbers[i], numbers[j] = numbers[j], numbers[i] if numbers[i] > numbers[left]: numbers[i-1], numbers[left] = numbers[left], numbers[i-1] else: numbers[i], numbers[left] = numbers[left], numbers[i] quick_sort(numbers,left,i-1) quick_sort(numbers,i+1,right) return numbers test = [3,7,8,5,1,2,2,2,22,11,5,4] print(quick_sort(test, 0, len(test) - 1)) ~~~ |
4
czheo OP ~~~
def quick_sort(numbers,left,right): if right - left <= 0: return numbers tmp = numbers[left] i = left + 1 j = right while i < j: while numbers[j] > tmp and i < j: j -= 1 while numbers[i] <= tmp and i < j: i += 1 numbers[i], numbers[j] = numbers[j], numbers[i] if numbers[i] > numbers[left]: numbers[i-1], numbers[left] = numbers[left], numbers[i-1] else: numbers[i], numbers[left] = numbers[left], numbers[i] quick_sort(numbers,left,i-1) quick_sort(numbers,i+1,right) return numbers test = [3,7,8,5,1,2,2,2,22,11,5,4] print(quick_sort(test, 0, len(test) - 1)) ~~~ |