def bubble_sort(items):
    """Sort given items by swapping adjacent items that are out of order, and
    repeating until all items are in sorted order.
    Running time: O(n^2) because as the input grows so does both of the loops
    Memory usage: O(1) because not creating any new space and everything is done in place"""
    array_length = len(items) - 1
    
    # goes through the list and looks at the next item and if it's smaller than current item then swap, else it continues down the list. The loop is repeated however many times it needs to and stops when no swapping occurs. 
    # the number of passes that needs to go before instance of no swap or go through each item with one pass
    while array_length > 0:
        swap = False
        for i in range(array_length):
            if items[i+1] < items[i]:
                items[i], items[i+1] = items[i+1], items[i]
                swap = True
        # the while loop breaks if during this pass there was not a swap
        if not swap:
            break
        array_length -= 1

    return items