Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Solve in Python ASAP (max within the next hour) , please. In the code below, the selection-sort function repeatedly finds the smallest number in the

Solve in Python ASAP (max within the next hour), please.

In the code below, the selection-sort function repeatedly finds the smallest number in the current list and swaps it with the first one. Rewrite this program by finding the largest number and swapping it with the last one. Write a test program that reads in numbers entered in one line, invokes the function, and displays the sorted numbers.

THE CODE IS COPIED BELOW BUT PLEASE POST ONE WITH THE INDENTATIONS AND A TEST RUN. THANK YOU!

image text in transcribed

def selectionSort(lst):

for i in range(len(lst) - 1):

# Find the minimum in the lst[i : len(lst)]

currentMin = min(lst[i : ])

currentMinIndex = i + lst[i: ].index(currentMin)

# Swap lst[i] with lst[currentMinIndex] if necessary

if currentMinIndex != i:

lst[currentMinIndex], lst[i] = lst[i], currentMin

def main():

lst = [-2, 4.5, 5, 1, 2, -3.3]

selectionSort(lst)

print(lst)

main()

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

More Books

Students also viewed these Databases questions

Question

Construct the Bode plots for G(s) = s + 1/s2(s + 10), s = j

Answered: 1 week ago

Question

1. Explain how business strategy affects HR strategy.

Answered: 1 week ago