We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1fe9acb commit 117c476Copy full SHA for 117c476
ehco/quick_sort/sort.py
@@ -0,0 +1,21 @@
1
+def quicksort(array):
2
+ size = len(array)
3
+ if not array or size < 2:
4
+ return array
5
+ pivot_idx = 0
6
+ pivot = array[pivot_idx]
7
+ less_part = [array[i] for i in range(size) if array[i] <= pivot and pivot_idx != i]
8
+ great_part = [array[i] for i in range(size) if array[i] > pivot and pivot_idx != i]
9
+ return quicksort(less_part) + [pivot] + quicksort(great_part)
10
+
11
12
+def test_quicksourt():
13
+ import random
14
15
+ seq = list(range(10))
16
+ random.shuffle(seq)
17
+ assert quicksort(seq) == sorted(seq)
18
19
20
+if __name__ == "main":
21
+ test_quicksourt()
0 commit comments