forked from hackclubsal/30DayOfPython
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day-15 by_Aaditya
35 lines (26 loc) · 845 Bytes
/
Day-15 by_Aaditya
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#day15_challenge
n=int(input("enter size of array"))
array=[]
for i in range(0,n):
x=int(input("enter element"))
array.append(x)
print("Before sorting:",array)
def partition(start, end, array):
pivot_index = start
pivot = array[pivot_index]
while start < end:
while start < len(array) and array[start] <= pivot:
start += 1
while array[end] > pivot:
end -= 1
if (start < end):
array[start], array[end] = array[end], array[start]
array[end], array[pivot_index] = array[pivot_index], array[end]
return end
def quick_sort(start, end, array):
if (start < end):
p = partition(start, end, array)
quick_sort(start, p - 1, array)
quick_sort(p + 1, end, array)
quick_sort(0, len(array) - 1, array)
print(f'Sorted array: {array}')