WRITE A PYTHON PROGRAM TO PERFORM BUBBLE SORT TO SORT A DEFINED LIST
CODE FOR THE ABOVE PYTHON PROGRAM :
def bubbleSort(list):
for i in range(len(list)-1,0,-1):
for i in range(i):
if list[i]>list[i+1]:
temp = list[i]
list[i] = list[i+1]
list[i+1] = temp
list = [69,76,13,52,98,22,56]
bubbleSort(list)
print("\n The new Sorted list is : ",list,"\n")
WRITTEN CODE FOR THE ABOVE PROGRAM :
def bubbleSort(list):
for i in range(len(list)-1,0,-1):
for i in range(i):
if list[i]>list[i+1]:
temp = list[i]
list[i] = list[i+1]
list[i+1] = temp
list = [69,76,13,52,98,22,56]
bubbleSort(list)
print("\n The new Sorted list is : ",list,"\n")
OUTPUT :
my class teacher gave me this topic, this program really helped me to complete my work thank you.
ReplyDelete