Question
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!
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started