def order(L):
""" (list of numbers) -> None
Order L from smallest to largest. L is changed in-place. """
i=1
while i < len(L): j=i
while j > 0 and L[j] < L[j-1]:
L[j], L[j-1] = L[j-1], L[j] # swap L[j] and L[j-1] j=j-1
i=i+1
This question was done in tutorial. This took me a while to understand and figure out. I finally truly understood how to do it after the TA Christine did it on the board. The easiest way of thinking about figuring out how many steps there are is to think tally each step on the side of the code.
No comments:
Post a Comment