CP164 Lecture Notes - Lecture 3: G1 Phase, Radix Sort, If And Only If

234 views9 pages
1 Aug 2018
School
Course
Professor

Document Summary

__updated__ = 2017-08-25 from math import log from list_linked import list class sorts: Uses class attribute "swaps" to determine how many times elements are swapped by the class. Use: sorts. swaps = 0 swaps = 0 # tracks swaps performed. Sorts a linked list using the selection sort algorithm. # go through each node in the unsorted list and find the max value. # remove the max node from the list. Sorts. swaps += 1 if max_prev is none: unsorted = max_node. _next else: max_prev. _next = max_node. _next. # move the next max node to the front of the sorted list. max_node. _next = a. _front a. _front = max_node return. Sorts a linked list using the bubble sort algorithm. Contents of a are sorted. done = false last = none while not done: # if no elements have been swapped, then the list is sorted done = true.

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