forked from souravjain540/Basic-Python-Programs
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuick_sort.py
More file actions
Latest commit
17 lines (15 loc) · 472 Bytes
/
Copy pathQuick_sort.py
File metadata and controls
17 lines (15 loc) · 472 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# Quick sort algorithm
defquicksort(array):
iflen(array) <=1:
returnarray
else:
pivot=array.pop()
items_greater= []
items_lower= []
foriteminarray:
ifitem>pivot:
items_greater.append(item)
else:
items_lower.append(item)
returnquicksort(items_lower) + [pivot] +quicksort(items_greater)
print(quicksort([3, 5, 1, 2, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]))