from create_list import random_list, is_sorted


def bubble_sort(my_list):
    """
    Perform bubble sort on my_list.
    """
    while not is_sorted(my_list):
        for i in range(len(my_list) - 1):
            if my_list[i] > my_list[i + 1]:
                my_list[i], my_list[i + 1] = my_list[i + 1], my_list[i]
    return my_list


my_list = random_list(50)
print(my_list)
print(is_sorted(my_list))

sorted_list = bubble_sort(my_list)
print(sorted_list)
print(is_sorted(sorted_list))
Example #2
0
                l += 1
            elif (not left_value == None and not right_value == None and left_value >= right_value) or (
                not left_value and not left_value == 0
            ):
                my_list[i] = right_value
                r += 1
            else:
                raise Exception

    if len(my_list) <= 1:
        return

    left = my_list[0 : (len(my_list) / 2)]
    right = my_list[(len(my_list) / 2) :]
    merge_sort(left)
    merge_sort(right)

    __merge(left, right)

    return my_list


# my_list = [15, 73, 57, 15, 43, 94, 13, 11, 34, 87, 100, 82, 0]
my_list = random_list(14)
print(my_list)
print(is_sorted(my_list))

sorted_list = merge_sort(my_list)
print(sorted_list)
print(is_sorted(sorted_list))
Example #3
0
from create_list import random_list, is_sorted


def bubble_sort(my_list):
    """
    Perform bubble sort on my_list.
    """
    while not is_sorted(my_list):
        for i in range(len(my_list) - 1):
            if my_list[i] > my_list[i + 1]:
                my_list[i], my_list[i + 1] = my_list[i + 1], my_list[i]
    return my_list

my_list = random_list(50)
print(my_list)
print(is_sorted(my_list))

sorted_list = bubble_sort(my_list)
print(sorted_list)
print(is_sorted(sorted_list))