0IggyMarie0
16.04.2020 •
Computers and Technology
Descending selection sort with output during execution
Write the function selection_sort_descend_trace() that takes an integer list and sorts the list into descending order. The function should use nested loops and output the list after each iteration of the outer loop, thus outputting the list N-1 times (where N is the size).
Complete __main__ to read in a list of integers, and then call selection_sort_descend_trace() to sort the list.
Ex: If the input is:
20 10 30 40
then the output is:
40 10 30 20
40 30 10 20
40 30 20 10
# TODO: Write a selection_sort_descend_trace() function that
# sorts the numbers list into descending order
def selection_sort_descend_trace(numbers):
if __name__ == "__main__":
# TODO: Read in a list of integers into numbers, then call
# selection_sort_descend_trace() to sort the numbers
numbers = []
Solved
Show answers
More tips
- W Work and Career What is the Most In-Demand Profession in the Modern World?...
- A Auto and Moto How Can Parking Sensors Help Drivers?...
- H Health and Medicine What is the Normal Blood Sugar Level in a Healthy Person?...
- F Food and Cooking Red Caviar: How to Choose the Best?...
- C Computers and Internet Clearing Cache: How to Speed Up Your Browser...
- S Style and Beauty How are artificial nails removed?...
- S Style and Beauty Secrets of Tying a Pareo: 5 Ways...
- F Food and Cooking Everything You Need to Know About Pasta...
Answers on questions: Computers and Technology
- M Mathematics In the number 1,435,976, in what place value is the 3?...
- M Mathematics Emilia waited 11 minutes for the bus today. That is 4 minutes less than she waited yesterday. How long did Emilia wait for the bus yesterday?...
- S Social Studies Why do many hunters choose a recurve crossbow instead of a compound crossbow?...
- M Mathematics The average age of the residents in a city is 40 and the standard deviation is 17 years. The distribution of ages is known to be normal. Suppose a group of 15 people is formed...
- M Mathematics Which statement is true? O A checking account is where you want to keep your spending money and a savings account is where you want to keep your savings. O A checking is account...
Ответ:
Check the explanation
Explanation:
Please find the code down
def selection_sort_descend_trace(numbers):
i=len(numbers)
print("Output: ")
for num in range(0,i-1):# traversing from 0 to N-2, total N-1 iterations
val=numbers[num]
start=num+1
end=i
t=0
for j in range(start,end):
if(val<numbers[j]):
remember=j
val=numbers[j]
t=1
if(t==1):# swaping onlf if greater number is available
temp=numbers[num]
numbers[num]=val
numbers[remember]=temp
for p in range(i):# printing
print(numbers[p],end=' ')
print("\n")
if __name__ == "__main__":
print("Enter the integers separated by space: ")
numbers=[int(x) for x in input().split(' ')]
selection_sort_descend_trace(numbers)
Taking input as string and splitting with space as delimiter , converting the split part to integer , finally append in the list.
Ответ:
i do but nO
Explanation:
ur a p00p bu77