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 kind of heat we feel from the sun
ivolga24 [154]

Is it solar heat? ultraviolet heat? UV?
6 0
3 years ago
Read 2 more answers
Analyze the following code. Which of the following statements is correct?
matrenka [14]

Answer:

that is complex wow

Explanation:

8 0
3 years ago
A company organizes all of its client database in order of the amount of money that the account is worth. When a new account is
svet-max [94.6K]

Answer:

The addition and count algorithm

Explanation:

3 0
2 years ago
What is one advantage of top-down programming design?
mojhsa [17]

Answer:

Programmers can take advantage of abstraction to focus on specific tasks.

Explanation:

When we excel in some subjects, we can do abstraction in that subject. Abstraction means you understand by the term, and you do not need details of that term. Like you say some tasks will be done by a graphic designer as a project manager, and you do not need to understand at that point what he will be doing, and that is because you can write in a word or few what is going to be the outcome. And hence, the programmers can take advantage of abstraction to focus on specific tasks. And this is the correct option.

5 0
3 years ago
Read 2 more answers
True or False? At any point in time, an open file has a current file pointer indicating the place where the next read or write o
mr_godi [17]

Answer:

True is the correct answer for the above question.

Explanation:

  • When any document file is opened then every point has some particular address. so there is a pointer which states that where the read operation and the write operation is going on.
  • When any person writes any program to read a file or write a file then there is a need for some variable that is pointed for the reading and the write operation.
  • The document which is used for the write data or read data is also designed and maintained by some software.
  • Hence we can say that there are needs of some variable that point the operation of the file and it is also stated from the above question. Hence the above question statement is a true statement.
5 0
3 years ago
Other questions:
  • How does the use of modules provide flexibility in a structured programming design?
    14·2 answers
  • If you enjoy working with livestock, the best cluster in which to research careers would be: A. Health Science. B. Agriculture,
    11·1 answer
  • A stop sign is an example of?
    11·2 answers
  • Write a class for a Cat that is a subclass of Pet. In addition to a name and owner, a cat will have a breed and will say "meow"
    14·1 answer
  • Describe the process of sorting the following list using the above algorithm:
    7·1 answer
  • When you are working in Performance Monitor, in the "Add Counters" dialog box, and need more information about a particular coun
    8·1 answer
  • ASAP BRAINLIEST!!!
    6·1 answer
  • Area Triangolo Rettangolo in c++
    6·1 answer
  • What is the simplest form of backing up data?
    10·1 answer
  • What is software?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!