Monday, 24 January 2022

Write a python script to implement bubble sort using list

Slip 22 Q 2

CODE :


def bubble_sort(list1):
    for i in range(0,len(list1)-1):  
        for j in range(len(list1)-1):  
            if(list1[j]>list1[j+1]):  
                temp = list1[j]  
                list1[j] = list1[j+1]  
                list1[j+1] = temp  
    return list1  
 
list1 =[]
n=int(input('Enter number of elements : '))
for i in range(n):
    value=int(input())
    list1.append(value)
print("The unsorted list is: ", list1)  

print("The sorted list is: ", bubble_sort(list1))

OUTPUT:




No comments:

Post a Comment

Write a Java program to display given extension files from a specific directory on server machine.

 DOWNLOAD     SLIP14Q2 /** * STEPS TO RUN CODE * Step 01 compile the code * Step 02 run the code * Step 03 give a file directory locatio...