Advertisement
MarkEd

Untitled

Jul 30th, 2014
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. def bubbleSort(lis): #This function sorts a list with "bubble sort".
  2. for i in range(len(lis)):
  3. for j in range(len(lis)-1-i):#"-i" becuase after the iteration it is already sorted, so we don't have to check it.
  4. if lis[j].num_ships() < lis[j+1].num_ships(): #Check which number is bigger.
  5. lis[j], lis[j+1] = lis[j+1], lis[j] #Swap if needed.
  6. return lis #returns the list sorted
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement