1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
vazorg [7]
2 years ago
12

Design a program takes as input, X, an unsorted list of numbers, and returns the sorted list of numbers in X. The program must b

e based on the following strategy: Handle the case when X is empty and has only 1 item. Split X into two lists, using the split function in the previous problem. Sort L and G. Put everything together into a sorted list. Test your program with 10 different unsorted lists.
Computers and Technology
1 answer:
Lelechka [254]2 years ago
7 0

Answer:

The program in python is as follows:

def split(X):

   L = []; G = []

   for i in range(len(X)):

       if X[i]>=X[0]:

           G.append(X[i])

       else:

           L.append(X[i])

   L.sort(); G.sort()

   return L,G

X = []

n = int(input("Length of X: "))

for i in range(n):

   inp = int(input(": "))

   X.append(inp)

   

if len(X) == 0 or len(X) == 1:

   print(X)

else:

   X1,X2=split(X)

   newList = sorted(X1 + X2)

   print(newList)

Explanation:

The following represents the split function in the previous problem

def split(X):

This initializes L and G to empty lists

   L = []; G = []

This iterates through X

   for i in range(len(X)):

All elements of X greater than 0 equal to the first element are appended to G

      <em> if X[i]>=X[0]:</em>

<em>            G.append(X[i])</em>

Others are appended to L

<em>        else:</em>

<em>            L.append(X[i])</em>

This sorts L and G

   L.sort(); G.sort()

This returns sorted lists L and G

   return L,G

The main function begins here

This initializes X

X = []

This gets the length of list X

n = int(input("Length of X: "))

This gets input for list X

<em>for i in range(n):</em>

<em>    inp = int(input(": "))</em>

<em>    X.append(inp)</em>

This prints X is X is empty of has 1 element

<em>if len(X) == 0 or len(X) == 1:</em>

<em>    print(X)</em>

If otherwise

else:

This calls the split function to split X into 2

   X1,X2=split(X)

This merges the two lists returned (sorted)

   newList = sorted(X1 + X2)

This prints the new list

   print(newList)

You might be interested in
What should be used to screw on broadheads? needle-nose pliers gloves thumb and forefinger only specially designed wrench
strojnjashka [21]
You should use needle-nose pliers, or sometimes even specially designed wrenches to screw on broadheads. 
3 0
2 years ago
Most file managers include a way to create a folder through the save dialog box. true or false?
Illusion [34]

Answer:

false because most of the file managers just keep Everything organized by dates, years, and everything like that

Explanation:

5 0
2 years ago
a user has a large amount of data that she or he needs to store. the data will not be accessed regularly, but still needs to be
Flura [38]
You need a sd card so you can store it and use it later
6 0
3 years ago
Read 2 more answers
A mother age is formed by reversing the two digits of daughters age. If the mother is 18 years older than daughter and sum of th
Gwar [14]
I'm not absolutely positive that my answer is correct... but here's what I got...

Mother: 33 years old

Daughter: 15 years old
4 0
3 years ago
List the general steps that are used to configure a soho router and set up the network
marusya05 [52]
Configure the Internet connection. 

Configure the wireless router. 

Enable NAT. 

Configure DHCP

Secure the SOHO network.
7 0
3 years ago
Other questions:
  • Information permanently stored on a hard disk, diskette, cd-rom disk, or tape, is called ________ storage.
    8·1 answer
  • Helppppppppppppppppppp
    11·1 answer
  • PLEASE HELP ME ASAP!!!!
    11·1 answer
  • List any feature of drwing toolbal​
    5·1 answer
  • Which is a basic job requirement for a career in corrections services?
    13·1 answer
  • How do I find a back door password on my computer?
    12·1 answer
  • Discuss five processes for analyzing a qualitative study
    11·2 answers
  • Write a program that uses a structure to store the following data about a customer account: Name Address City, State, and ZIP Te
    10·1 answer
  • Which element of the MakeCode Arcade interface represents an individual
    12·1 answer
  • you are asked to create a four-digit code using the numbers from 1 to 9. how many possible codes are there--assuming that number
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!