Let A be an array of size n. Choose the first value as pivot. Write a program to partition the array based on the pivot value so that all values to
the left of pivot are lesser and right of pivot are greater than the pivot.For example, if A = [60, 67, 34, 23, 32, 54, 76] is the input, the output has to be A =[23, 54, 34, 32, 60, 67, 76]. Since 60 is the pivot, left of 60 are lesser than 60 and the right values are greater than 60
A=[60, 67, 34, 23, 32, 54, 76]
pivot=A[0]
x=[]
y=[]
A.sort()
for i in A:
if i<pivot:
x.append(i)
for i in A:
if i>pivot:
y.append(i)
x.append(pivot)
for i in y:
x.append(i)
print(x)
Comments
Leave a comment