CMPT-101 Lecture 13: Sorting Lists

97 views1 pages

Document Summary

#find the largest. def find_largest (nums, n): largest = nums[0] position = 0 for i in range (1,n): if nums[i] > largest: largest = nums position = i return position. #to sort a list, find the largest number from an unsorted list and place it last in the list. #then find the largest number from the unsorted list again and place it next to that one. #the number of comparisons is equal to the length of the list minus one.

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

Related Questions