Question
Write a program in which you manually sort a list of integers from 0 to 9. You can use the following code at the top
- Write a program in which you manually sort a list of integers from 0 to 9. You can use the following code at the top of your program to generate and randomize the list unordered:
import random
unordered = list(range(10))
ordered = []
random.shuffle(unordered)
You can use an established method to sort the list called the Selection Sort. Heres the pseudocode for an implementation of the Selection Sort algorithm that removes elements from an original, unordered list and appends them to a new, ordered list:
Create an empty list to hold the ordered elements
While there are still elements in the unordered list
Set a variable, lowest, to the first element in the unordered list
For each element in the unordered list
If the element is lower than lowest
Assign the value of that element to lowest
Append lowest to the ordered list
Remove lowest from the unordered list
Print out the ordered list
An important point to remember is that Pythons implementation of list sorting is far more efficient than this implementation of the Selection Sort. So, when you want to sort a list (other than for this project), you should use the built-in sort() list method.
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