forked from fnplus/hacktoberfest-algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquick_sort.py
More file actions
24 lines (20 loc) · 759 Bytes
/
Copy pathquick_sort.py
File metadata and controls
24 lines (20 loc) · 759 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
""" Created by SubCoder1 on 15-Oct-18.
Sorting Technique -- Quick Sort
Input -- A sequence of n numbers
Output -- Reordered into a definite sequence {Ascending(HERE)}
Time Complexity :-
Worst Case - O(N^2)
Best Case - O(NLogN) """
def q_sort(array) :
if len(array) > 0 :
left = list() ; right = list() ; equal = list()
pivot = array[0]
for element in array :
if element < pivot : left.append(element)
elif element > pivot : right.append(element)
else : equal.append(element)
return q_sort(left) + equal + q_sort(right)
else :
return array
array = list(map(int, input().split()))
print(*q_sort(array), end='')