Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def bubbleSort(lis): #This function sorts a list with "bubble sort".
- for i in range(len(lis)):
- 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.
- if lis[j].num_ships() < lis[j+1].num_ships(): #Check which number is bigger.
- lis[j], lis[j+1] = lis[j+1], lis[j] #Swap if needed.
- return lis #returns the list sorted
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement