Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

  1. 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

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

Students also viewed these Databases questions

Question

1. What are the pros and cons of diversity for an organisation?

Answered: 1 week ago

Question

1. Explain the concept of diversity and equality in the workplace.

Answered: 1 week ago