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
By default, which of these traffic source dimensions does google analytics capture for each user that visits your website?
natta225 [31]

The question above has multiple choices as listed;

<span />a. Source and Medium<span>
</span>

<span>b. Campaign and Ad Content</span>
<span />

<span>c. Campaign and Medium
</span><span>
</span><span>d. Source, Medium, Campaign, and Ad Content
</span>
<span />

<span>The correct answer is A. Source and Medium</span>

Source and medium combines the dimensions source and medium. Anyone referred to a website has an origin or a source. Examples of possible sources include Google, Facebook.com, and direct for those who typed your URL directly. Every referral, on the other hand, has a medium and possible examples of medium include organic, cost per click, referral, email, and none.






5 0
3 years ago
To control how and when the slides should appear during the slide show, we use the__________________ feature​
jekas [21]

Answer:

Slide transition

Explanation:

See open chapter 4 page 49 and you will get it

8 0
3 years ago
You visit two websites about inventions of the 21st century. One has .edu in the URL address and the other has .com. Which site
Kobotan [32]
Since you are searching for researching information, .edu will be more reliable.

.edu is for education purpose, with credits of scholars.

.com is a general URL, it's not relavant to reliability.
4 0
3 years ago
Read 2 more answers
Where can you access email accounts on your windows 7 computer in order to modify current accounts or create new ones?
Mademuasel [1]
I'll create new ones because just for me, its so hassle
8 0
3 years ago
What are Operating Systems?
horrorfan [7]

Answer:

the software that supports a computer's basic functions, such as scheduling tasks, executing applications, and controlling peripherals.

5 0
2 years ago
Other questions:
  • A ____ is harmful computer code that spreads without your interaction, slipping from one network to another and replicating itse
    15·1 answer
  • Can someone please help me write a code for this
    7·1 answer
  • What is the use of word art?
    10·1 answer
  • 7. What is the school campus’s setting<br> the school is sanford
    6·2 answers
  • A _______ is smaller than a notebook or laptop and has a touchscreen and sometimes a pointing device.
    13·1 answer
  • A broadband router is used to do which of the following? run the programs on a computer locate lost files on a computer manage a
    6·1 answer
  • In your own words, describe what Internet Protocols are. Why is it important to have agreed upon protocols?
    6·1 answer
  • Is a biometric system an input, output, storage or soft device?​
    6·1 answer
  • Fill in the blank: _____ data are statistical and numerical facts about a project.
    15·2 answers
  • A user may enter some text and the number of times (up to a maximum of 10) to repeat it. Display the text repeated that many tim
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!