#! /usr/bin/python
# https://github.com/jackchi/interview-prep
import random
# Bubble Sort

# randomly generate 10 integers from (-100, 100)
arr = [random.randrange(-100,100) for i in range(10)]

print('original %s' % arr)
def bubbleSort(array):
  



a = bubbleSort(arr)
print(f"sorted {a}")


n = len(array)
  # traverse thru all elements
  for i in range(n):
    swapped = False
    # traverse thru last i elements already sorted
    for j in range(0, n-i-1):
      # swap smaller to front
      if array[j] > array[j+1]: 
        array[j], array[j+1] = array[j+1], array[j] 
        swapped = True
    
    # IF no two elements were swapped 
    # by inner loop, then break 
    if swapped == False: 
        break
      
  return array