Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Task 4: Sorting Tables In the lectures you were given the following code for insertion sort: def insert (k, Ist): j - k while j

image text in transcribed
Task 4: Sorting Tables In the lectures you were given the following code for insertion sort: def insert (k, Ist): j - k while j > 0 and 1st [j-1] > Ist [j]: Ist [j-1] , Ist [j] = 1st [j], Ist [j-1] j = j - 1 def insertion_sort (1st) : for i in range (1, len (n)) : insert (i, Ist) Implement a function sort.table(table, col) that takes as input an n x m table and a column index. The function sorts the rows of the table in non-decreasing order according to the values in the given column. The function does not have a return statement. You should model your function on the insertion sort code. Example: say that we have the following table: jedi = [['Luke' , 'Tatooine' , 'green'], ['Qui-Gon' , 'Coruscant', 'blue'], ['Obi-Wan' , 'Coruscant', 'blue'], ['Rey' , 'Jakku' , 'yellow']] After calling sort_table (jedi, 0), then jedi == [['Luke', 'Tatooine', 'green'], ['Obi-Wan', 'Coruscant', 'blue'], ['Qui-Gon' , 'Coruscant', 'blue'], ['Rey', 'Jakku', 'yellow']]. If we then call sort.table (jedi, 2), then jedi == [['Obi-Wan', 'Coruscant' , 'blue'], ['Qui-Gon', 'Coruscant', 'blue'], ['Luke', 'Tatooine' , 'green'], ['Rey' , 'Jakku', 'yellow']]. Note that the relative ordering is maintained

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

Students also viewed these Programming questions