CP104 Lecture Notes - Lecture 12: Bubble Sort, Merge Sort, Insertion Sort

264 views3 pages
17 Jun 2017
School
Course
Professor
hayjayshay and 38575 others unlocked
CP104 Full Course Notes
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.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents