CP104 Lecture Notes - Lecture 12: Bubble Sort, Merge Sort, Insertion Sort
hayjayshay and 38575 others unlocked
2
CP104 Full Course Notes
Verified Note
2 documents
Document Summary
# imports import random from list_linked import list from number import number from sorts_linked import sorts. Size = 100 # size of array to sort. Xrange = 1000 # range of values in random arrays to sort. Tests = 100 # number of random arrays to generate. Sorts = ( ("bubble sort", sorts. bubble_sort), ("insertion sort", sorts. insertion_sort), ("merge sort", sorts. merge_sort), ("quick sort", sorts. quick_sort), ("selection sort", sorts. selection_sort), def create_sorted(): Postconditions: returns: values - a sorted list of size number objects (list) values = list() i = 0 while i < size: values. append(number(i)) i += 1 return values def create_reversed(): Postconditions: returns values - a reversed list of size number objects (list) values = list() i = 0 while i < size: values. insert(0,number(i)) i += 1 return values def create_randoms(): Test a sort function with number data and print out its comparisons for sorted, reversed, and random lists of data.