Objectives
- Discuss the order of different sorting algorithms
- Implement an array or list sort
def is_sorted(ar): for i in range(0, len(ar)-1): if ar[i] > ar[i+1]: return False return True def bubble_sort(ar): n = len(ar) swapped = True while swapped: swapped = False for i in range(1, n): if ar[i-1] > ar[i]: ar[i-1], ar[i] = ar[i], ar[i-1] swapped = True n = n - 1 lst = [] import random for i in range(2000): n = random.randint(1, 5000) while n in lst: n = random.randint(1, 5000) lst.append(n) print("List sorted before sort: ", is_sorted(lst)) bubble_sort(lst) print("List sorted after sort: ", is_sorted(lst))