Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

COMPUTER PROJECT

Name: Joyit Aryan Narang


Class: XI
Section: BS1
Roll no. : 17
L=[]

n=int(input("Enter the size of the list"))

print("Enter the numbers:")

for i in range(0,n):

x=int(input(""))

L.append(x)

print("--------MENU--------")

print("1.Sort the list")

print("2.Search for an element in the list")

choice=int(input("Enter your choice:"))

if choice==1:

print("------MENU------")

print("1.Bubble Sort")

print("2.Selection Sort")

print("3.Insertion Sort")

choice1=input("Enter your choice")

if choice1==1:
for i in range(0,n-1):

for j in range(0, n-i-1):

if arr[j]>arr[j + 1]:

arr[j],arr[j+1]=arr[j+1],arr[j]

elif choice1==2:

for i in range(0,n):

min_index=i

for j in range(i+1,n):

if min_index>L[j]:

min_index,L[j]=L[j],min_index

L[i],L[min_index]=L[min_index],L[i]

elif choice1==3:

for i in range(1,n):

key=L[i]

j=i-1

while j>=0 and key<arr[j]:

arr[j+1]=arr[j]

j-=1

arr[j+1]=key

print(L)

elif choice==2:

element=int(input("Enter the element to be searched"))

print("------MENU------")

print("1.Linear Search")

print("2.Binary Search")

choice2=int(input("Enter your choice:"))

if choice2==1:
found=False

for i in range(0,n):

if L[i]==element:

found=True

print("Element found at index ",i)

if found==False :

print("Element not found")

if choice2==2:

for i in range(0,n-1):

for j in range(0, n-i-1):

if arr[j] > arr[j + 1]:

arr[j], arr[j + 1] = arr[j + 1], arr[j]

found1=False

low=0

high=n-1

mid=0

while low<=high:

mid=(high+low)//2

if L[mid]<element:

low=mid+1

elif L[mid]>element:

high=mid-1

else:

print("Element found at ",mid)

found1=True

if found1==False :

print("Element not found")

You might also like