Question: Convert this pseudo code into python 3: The pseudo code: function partition(A,start,stop) Set pivot = A[stop] Set i=start for j from start to stop by

Convert this pseudo code into python 3:

The pseudo code:

function partition(A,start,stop)

Set pivot = A[stop]

Set i=start

for j from start to stop by 1 do

if not (A[j] > pivot) then

Swap A[i] and A[j]

Add 1 to i

end if

end for

Swap A[i] and A[stop]

return i

end function

This following program below is a separate file that tests the partition program (the pseudo code above)

from part import partition: def checkP(X,start,stop,p): pivot = X[p] for v in range(0,p): if X[v] > pivot: return False for v in range(p,stop+1): if X[v] < pivot: return False return True def runTest(test,input): data = test start = input[0] stop = input[1] print("Partitioning List:") print(data) print("Start=%d, Stop=%d"%(start,stop)) p=partition(data,start,stop) if checkP(data,start,stop,p): print("Partition is valid.") else: print("Partition is invalid.") print("After Partition:") print(data)

if __name__=="__main__": T=[ [] for x in range(0,6)] inputs = [ [] for x in range(0,6)] #Simple test T[0]=[1,9,2,8,3,7,4,6] inputs[0]=[0,7] #Left Border T[1]=[1,9,2,8,3,7,4,6] inputs[1]=[0,2] #Right Border T[2]=[1,9,2,8,3,7,4,6] inputs[2]=[5,7] #Middle Case T[3]=[1,9,2,8,3,7,4,6] inputs[3]=[2,5] #Bad Case Left T[4]=[1,2,3,4,5,6,7,8,9] inputs[4]=[0,8] #Bad Case Right T[5]=[9,8,7,6,5,4,3,2,1] inputs[5]=[0,8] #Run tests counter=0 while counter < len(T): print("Test %d of %d."%(counter+1,len(T))) runTest(T[counter],inputs[counter]) counter+=1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!