We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Use the Quicksort algorithm to sort the entire array
def sorting(ar):
if len(ar) <= 1:
return ar
left, equal, right = partition(ar)
merging_arr = sorting(left) + equal + sorting(right)
print (' '.join(str(e) for e in merging_arr))
return merging_arr
def partition(ar):
left, equal, right=[],[ar[0]],[]
for elem in ar[1:]:
if elem < ar[0]:
left.append(elem)
elif elem == ar[0]:
equal.append(elem)
else:
right.append(elem)
return left, equal, right
if name == 'main':
n = input()
ar = list(map(int,input().rstrip().split()))
sorting(ar)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Quicksort 2 - Sorting
You are viewing a single comment's thread. Return to all comments →
Use the Quicksort algorithm to sort the entire array
def sorting(ar):
def partition(ar):
if name == 'main':