B45 Selection Bubble Sort
B45 Selection Bubble Sort
DIV:-B45
Write a Python program to store first year percentage of students in array. Write a function for
sorting array of floating point numbers in ascending order using
a) Selection Sort
b) Bubble Sort and display top five scores
"""
Write a Python program to store first year percentage of students in
array. Write a function for sorting array of floating point numbers in
ascending order using
a) Selection Sort
b) Bubble Sort and display top five scores
"""
def SelectionSort(arr,n):
for i in range(n):
Min = i
for j in range(i+1,n):
if(arr[j]<arr[Min]):
Min = j
temp=arr[i]
arr[i]=arr[Min]
arr[Min]=temp
print(arr)
def BubbleSort(arr,n):
i = 0
for i in range(n-1):
for j in range(0,n-i-1):
if(arr[j] > arr[j+1]):
temp = arr[j]
arr[j] = arr[j+1]
arr[j+1] = temp
print(arr)
print("Top Five Scores are...")
for i in range (len(arr)-1,1,-1):
print(arr[i])
#Driver Code
print("\nHow many students are there?")
n = int(input())
array = []
i=0
for i in range(n):
print("\n Enter percentage marks")
item = float(input())
array.append(item)
OUTPUT :-
[35.0, 28.0, 79.0, 98.0, 46.0, 38.0, 67.0, 84.0, 37.0, 84.0]
Main Menu
1. Selection Sort
2. Bubble Sort
3. Exit
1. Selection Sort
2. Bubble Sort
3. Exit
1. Selection Sort
2. Bubble Sort
3. Exit