Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Solve in Python, please. In the code below, the selection-sort function repeatedly finds the smallest number in the current list and swaps it with the

Solve in Python, 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

Database Programming With Visual Basic .NET

Authors: Carsten Thomsen

2nd Edition

1590590325, 978-1590590324

More Books

Students also viewed these Databases questions

Question

List six ways that simulation can be used in business?

Answered: 1 week ago

Question

Please help me evaluate this integral. 8 2 2 v - v

Answered: 1 week ago

Question

8. Describe how cultural spaces are formed.

Answered: 1 week ago