//swap if left is larger than right //stop when nothing was swapped //complexity O(n2) func bubbleSort(s []int) { swapped := true for swapped { swapped = false for i := 1; i < len(s); i++ { if s[i-1] > s[i] { temp := s[i] s[i] = s[i-1] s[i-1] = temp swapped = true } } } }
on the algorithms However it is a little harder to see what is happening beneath the suffice. Limited to how much optimisation you can do by Python itself
= i while pos > 0 and arr[pos - 1] > cursor: # Swap the number down the list arr[pos] = arr[pos - 1] pos = pos - 1 # Break and do the final swap arr[pos] = cursor return arr