The following code implements this algorithm to sort a list of numbers in ascending order. But some code is missing as indicated by '?'.
def sort_in_place(list_num):
for i in range(?):
for j in range(?):
if ?:
temp = list_num[j]
list_num[j] = list_num[i]
list_num[i] = temp
my_list = [23,1,45,20,13,-34]
sort_in_place(my_list)
print(my_list)
The missing code that should come in place of '?' is given below :
for i in range(6):
for j in range(i+1,6):
if (list_num[i]>list_num[j]):
Here in our case, 6 is the number of elements in the list. You can change this value depending upon the number of elements in any list.
Complete Python program with output is given below.
Python Code :
def sort_in_place(list_num):
for i in range(6):
for j in range(i+1,6):
if (list_num[i]>list_num[j]):
temp = list_num[j]
list_num[j] = list_num[i]
list_num[i] = temp
my_list = [23,1,45,20,13,-34]
sort_in_place(my_list)
print(my_list)
Output :
If you have any doubt/query regarding the solution then let me know in comment. If it helps, kindly give an upVote to this answer.
Get Answers For Free
Most questions answered within 1 hours.