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)