Advertisement
Guest User

library

a guest
Apr 5th, 2020
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.98 KB | None | 0 0
  1. def kali(a,b):
  2.     result = a * b
  3.  
  4.     print(f"{a} x {b} = ",result)
  5.    
  6. def selectionsort(n,list1):
  7.  
  8.     i = 0
  9.     for i in range(0,n):
  10.         minIndex = i
  11.         for j in range(i+1,n):
  12.             if list1[minIndex] > list1[j]:
  13.                 minIndex = j
  14.         list1[i], list1[minIndex] = list1[minIndex], list1[i]
  15.  
  16. def bubblesort(n,list1):
  17.     swap = False
  18.     while not swap:
  19.         swap = True
  20.         for i in range(1,n):
  21.             if list1[i-1] > list1[i]:
  22.                 swap = False
  23.                 temp = list1[i]
  24.                 list1[i] = list1[i-1]
  25.                 list1[i-1] = temp
  26.     return list1
  27.  
  28. def insertionsort(n,list1):
  29.     for index in range(1,n):
  30.  
  31.         currentValue = list1[index]
  32.         position = index
  33.  
  34.         while position > 0 and list1[position - 1] > list1[position]:
  35.             list1[position] = list1[position-1]
  36.             position = position -1
  37.  
  38.         list1[position] = currentValue
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement