Skip to content

Commit ac37368

Browse files
Merge pull request #5 from Wendell00/main
add Quick_sort.py
2 parents c383860 + 2756f63 commit ac37368

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Quick_sort.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Quick sort algorithm
2+
3+
def quicksort(array):
4+
if len(array) <= 1:
5+
return array
6+
else:
7+
pivot = array.pop()
8+
items_greater = []
9+
items_lower = []
10+
for item in array:
11+
if item > pivot:
12+
items_greater.append(item)
13+
else:
14+
items_lower.append(item)
15+
return quicksort(items_lower) + [pivot] + quicksort(items_greater)
16+
17+
print(quicksort([3, 5, 1, 2, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]))

0 commit comments

Comments
 (0)