In: Computer Science
I'm having trouble understanding the following code (a snippet of a code). What does it do? The whole code is about comparing efficiencies of different algorithms.
def partition(list,first,last):
piv = list[first]
lmark = first+1
rmark = last
done = False
while not done:
while lmark <= rmark and list[lmark]<=piv:
lmark=lmark+1
while list[rmark]>=piv and rmark>=lmark:
rmark=rmark-1
if rmark<lmark:
done = True
else:
temp = list[lmark]
list[lmark]=list[rmark]
list[rmark]=temp
temp = list[first]
list[first]=list[rmark]
list[rmark]=temp
return rmark
Sorry for the background test in the middle image but it is looking fine to understand that's why I'm uploading that image... .
I think now you got the picture of the given snippet gow it works for elements....
If you feel anything difficult to understand you can comment below and if you like the answer upvote it ......