Answer to Question #267453 in Python for kavin

Question #267453

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

1
Expert's answer
2021-11-17T17:37:22-0500
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)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS