You are on page 1of 1

WEEK3

#task 1
#Bubble sort
n=int(input("enter size of array:"))
print("enter the elements:")
a=list(map(int,input().split()))
for i in range(n-1):
    for j in range(n-1):
        if a[j]>a[j+1]:
            a[j+1],a[j]=a[j],a[j+1]
print(a)
 
#TASK2
#Insertion sort
n=int(input("enter size of array:"))
print("enter the elements:")
a=list(map(int,input().split()))
for i in range(n):
    if i>1:
     for j in range(i,0,-1):
        if a[j]<a[j-1]:
            a[j-1],a[j]=a[j],a[j-1]
print(a)
 
#task 3           
#Selction sort
l=list(map(int,input().split()))
for i in range(len(l)-1):
    for j in range(i+1,len(l)):
        if l[i]>l[j]:
            l[i],l[j]=l[j],l[i]
print(l)

You might also like