0% found this document useful (0 votes)
16 views2 pages

Program 3

The document contains Python functions for sorting an array using selection sort and bubble sort algorithms. It also includes a function to display the top five highest salaries from a given list. A sample salary list is provided, and the results of both sorting methods are printed along with the top five salaries.

Uploaded by

thoratgauri97
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views2 pages

Program 3

The document contains Python functions for sorting an array using selection sort and bubble sort algorithms. It also includes a function to display the top five highest salaries from a given list. A sample salary list is provided, and the results of both sorting methods are printed along with the top five salaries.

Uploaded by

thoratgauri97
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

def selection_sort(arr):

n = len(arr)

for i in range(n):

min_idx = i

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

if arr[j] < arr[min_idx]:

min_idx = j

arr[i], arr[min_idx] = arr[min_idx], arr[i]

def bubble_sort(arr):

n = len(arr)

for i in range(n):

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

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

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

def display_top_five(salaries):

print("\nTop Five Highest Salaries:")

# Reverse sort for highest first and take last 5

for sal in sorted(salaries, reverse=True)[:5]:

print(sal)

# Sample salary list

salaries = [45000.50, 55000.75, 32000.00, 67000.25, 72000.10,

88000.00, 50000.25, 61000.90, 70000.00, 93000.80]

print("Original Salaries:", salaries)


# Selection Sort

sel_sorted = [Link]()

selection_sort(sel_sorted)

print("\nSalaries after Selection Sort:", sel_sorted)

display_top_five(sel_sorted)

# Bubble Sort

bubble_sorted = [Link]()

bubble_sort(bubble_sorted)

print("\nSalaries after Bubble Sort:", bubble_sorted)

display_top_five(bubble_sorted)

You might also like