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]
3 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]3 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 is boolean rules​
masha68 [24]

Answer:

Boolean Algebra uses a set of Laws and Rules to define the operation of a digital logic circuit. As well as the logic symbols “0” and “1” being used to represent a digital input or output, we can also use them as constants for a permanently “Open” or “Closed” circuit or contact respectively.

6 0
3 years ago
| HELP PLS! C++ Sorting arrays can be performed using either Selection Sort or Insertion Sort or
Sholpan [36]

Answer:

wwhwwwwnlcw lcwl. wl w l. w la a. a. ac aa cw w w w. w. w. w w. ww w. w w w. w w w ww w w. w w ww. w cs s js jw jw kw kw ks jpsbp svkhs ksl oheo

8 0
3 years ago
What is a Limited Purpose credit card
Lynna [10]
A limited purpose credit means it can only be used for out of town references and not as a everyday use.
<span />
4 0
4 years ago
Read 2 more answers
Hy does a bus network need regular hubs if it is to cover very much ground?
Norma-Jean [14]
A bus network can only accommodate a number connections and a limited area. If there were more hubs connected to the bus network, the coverage of the network would be expanded and the number of connections will also be increased.
7 0
3 years ago
Whenever a program or command is executed, the kernel assigns an identification number called a(n) ____ to the process?
Furkat [3]
PID, process identification.
4 0
4 years ago
Other questions:
  • What can help establish the focus and organization it relies on?
    6·1 answer
  • What three characteristics of a function are described in an IPO chart? What is performed at each characteristic?
    12·1 answer
  • When a class contains a pointer to dynamically allocated memory, it is a good idea to equip the class with?
    9·1 answer
  • The computer mouse is used to
    7·2 answers
  • Assume a disk cache hit rate (dchr) of 95% and 2 millisecond on average to access a page in cache. If the average access time to
    8·1 answer
  • Compare and contrast Charles bebbage and Blaise Pascal inventions<br>​
    14·1 answer
  • Unlike when writing in a programming language, there are no set rules that must be followed when writing pseudocode. What do you
    13·1 answer
  • Write a program that accepts three decimal numbers as input and outputs their sum.
    10·1 answer
  • paula needs to ensure that an animation she has created is repeated. which option should she use to achieve this ?
    13·1 answer
  • A company is looking to share data between two platforms in order to extend their functionality. which feature enables communica
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!