fork(1) download
  1. def bubble_sort(arr):
  2. n = len(arr)
  3. for i in range(n):
  4. swapped = False
  5. for j in range(0, n - i - 1):
  6. if arr[j] > arr[j + 1]:
  7. arr[j], arr[j + 1] = arr[j + 1], arr[j]
  8. swapped = True
  9. if not swapped:
  10. break
  11. return arr
Success #stdin #stdout 0.08s 14088KB
stdin
12 5 7 4
stdout
Standard output is empty