-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathQuick_Sort.py
More file actions
23 lines (20 loc) · 746 Bytes
/
Quick_Sort.py
File metadata and controls
23 lines (20 loc) · 746 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#Runtime is O(nlogn)
def partition(start_index, end_index):
global array
pivot_value = array[end_index]
temp_pivot = start_index
for i in range(start_index, end_index):
if array[i] <= pivot_value:
array[temp_pivot], array[i] = array[i], array[temp_pivot]
temp_pivot += 1
array[temp_pivot], array[end_index] = array[end_index], array[temp_pivot]
return temp_pivot
def Quick_Sort(start_index, end_index):
global array
if start_index < end_index:
pivot_index = partition(start_index, end_index)
Quick_Sort(start_index,pivot_index - 1)
Quick_Sort(pivot_index + 1, end_index)
array = list(map(int, input().split()))
Quick_Sort( 0, len(array) - 1)
print(array)