CP104 Lecture Notes - Lecture 13: 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 number import number from sorts_array import sorts import copy. 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), ("bin. Sort", sorts. binary_insert_sort), ("cocktail sort", sorts. cocktail_sort), ("comb sort", sorts. comb_sort), ("heap sort", sorts. heap_sort), ("shell sort", sorts. shell_sort) def create_sorted(): Postconditions: returns values - a sorted list of size number objects. values = [] 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. values = [] i = 0 while i < size: values. append(number(i)) i += 1 values. reverse() return values def create_randoms(): Test a sort function with number data and print out its comparisons for sorted, reversed, and random arrays of data.