sidrs

FDS (LV) Ass 3 (Selection & Bubble Sort)

Aug 12th, 2024 (edited)
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.91 KB | None | 0 0
  1. def initMarks():
  2.     arr = []
  3.     n = int(input("Enter the number of Percentages to be added to the list: "))
  4.     for i in range(0, n):
  5.             ele = float(input("Enter the Percentage: "))
  6.             arr.append(ele)
  7.     return arr
  8.  
  9.  
  10. def selectSort(LIST):
  11.     for i in range(0, len(LIST)):
  12.         min = i
  13.         for j in range(i+1, len(LIST)):
  14.             if LIST[min] > LIST[j]:
  15.                 min = j
  16.         temp = LIST[min]
  17.         LIST[min] = LIST[i]
  18.         LIST[i] = temp
  19.     return LIST
  20.  
  21.  
  22. def bubbleSort(LIST):
  23.     for i in range(len(LIST)):
  24.         for j in range(len(LIST)):
  25.             if i == j:
  26.                 continue
  27.             else:
  28.                 if LIST[i] < LIST[j]:
  29.                     temp = LIST[i]
  30.                     LIST[i] = LIST[j]
  31.                     LIST[j] = temp
  32.     return LIST
  33.  
  34. percentages = initMarks()
  35. print(selectSort(percentages))
  36. print(bubbleSort(percentages))
  37.  
Advertisement
Add Comment
Please, Sign In to add comment