Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def bubblesortoptimised(arr):
- for i in range(len(arr)-1, 0, -1):
- issorted = True
- for j in range(i):
- if arr[j] > arr[j+1]:
- issorted = False
- arr[j], arr[j+1] = arr[j+1], arr[j]
- if issorted:
- print("The array is already sorted")
- break
- arr = [5, 6, 4, 3, 7, 3, 2, 8]
- bubblesortoptimised(arr)
- print(arr)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement