swadhinbiswas BATMAN IS GRATE · 3/15/2025
aaad9a6
50 lines · 1.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from typing import List
class Sorting:
  def bubbleshort(array:List[int]):
    isswap=False
    for i in range(0,len(array)-1):
      for j in range(0,len(array)-i-1):
        if array[j]>array[j+1]:
          array[j+1],array[j]=array[j],array[j+1]
          isswap=True
    return array

  def selectionssort(array:List[int])-> List[int]:
    n=len(array)
    for i in range(0,n):
      small_element:int=i
      for j in range(i+1,n):
        if array[j]<array[small_element]:
          small_element=j
      array[i],array[small_element]=array[small_element],array[i]
    return array

  def insertionsort(array:List[int])->List[int]:
    for i in range(1,len(array)):
      current=array[i]
      previous=i-1
      while previous>=0 and array[previous]>current:
        array[previous+1]=array[previous]
        previous-=1
        array[previous+1]=current

    return array












text=Sorting.bubbleshort([1,2,3,4,5])
text2=Sorting.selectionssort([3,4,5,1,3,5,6,7,9])
text3=Sorting.insertionsort([3,4,5,1,3,5,6,7,9])

print(text)
print(text2)
print(text3)