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
Anyone who know hacking​
Anton [14]

Answer: my best friend does her instgram is

user9294586

3 0
2 years ago
Late at night, some traffic signals change patterns and become _____.
SCORPION-xisa [38]
The answer is B.

Late at night, some traffic signals change patterns and become flashing yellow or red lights.
4 0
3 years ago
Read 2 more answers
What system calls have to be executed by a command interpreter? Why is it usually separate from the kernel?
Licemer1 [7]

Answer:

The exec command by interpreter to start new process

Explanation:

On Unix systems, a call to the fork system must be made followed by a call to the e x e c system to begin a new process. The fork call clones the process that is currently running, while the executive call overlays a new process based on a different executable over the calling process.

It is seperate from Kernal because

It Read user commands or a script and execute them, generally turning them into one or more system calls. Is usual It is not part of the kernel since the command interpreter is subject to change.

6 0
3 years ago
What was software for modems that connected through phone lines called?
balandron [24]

Answer:

Best Regards to all of the people who have met you in the class

4 0
3 years ago
How to bypass a Lightspeed and Rocket Filter blocked website without being a admin and without downloading extensions? Must incl
AVprozaik [17]

You really cant without being admin. Calm yaself child

6 0
3 years ago
Other questions:
  • A DSLR camera is made up of two parts. They are
    13·2 answers
  • Advantages of purchasing a software package over developing software in-house include all of the following except ____. Group of
    13·1 answer
  • 3. Before you get ready to go diving, you want to explore the area. You see a small snowpack across a small bridge, a short walk
    11·1 answer
  • The term "Big Data" is relative as it depends on the size of the using organization.
    14·1 answer
  • What kind of website uses keywords to locate content?
    15·1 answer
  • س2) اکتب خوارزميه لحل المعادلة الرياضيه الاتيه
    9·1 answer
  • A program that doesn’t work properly needs to be debugged. true or false
    8·1 answer
  • A power supply serves as both a rectifier and transformer to convert AC house current to DC and to step down voltage from 110 V
    6·1 answer
  • True or False? Popular sites are always mean accurate.
    14·2 answers
  • A statement that starts with a # symbol is called
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!