Untitled

 avatar
unknown
python
a year ago
944 B
6
Indexable
t = [4,7,5,3,0,9,1]

---------------------------
BUBBLE SORTING ALGORITHM:
---------------------------


temp = 0
print(t)
for i in range(0, len(t)-1):
    for i in range(0, len(t)-1):
        if t[i] > t[i + 1]:
            temp = t[i]
            t[i] = t[i + 1]
            t[i + 1] = temp
print(t)

---------------------------
SELECTION SORT ALGORITHM
---------------------------
t = [4,7,5,3,0,9,1]
print(t)
temp = 0
for i in range(0, len(t)):
    min = i
    switch = False
    for j in range(i, len(t)):
        if t[j] < t[min]:
            min = j
            switch = True
    if switch == True:
        temp = t[i]
        t[i] = t[min]
        t[min] = temp
print(t)
---------------------------
INSERTION SORT ALGORITHM
---------------------------
t = [4,2,5,3,0,6,1]
print(t)
temp = 0
for i in range(1, len(t)):
    temp = t[i]
    while t[i-1] > temp and i>0:
        t[i] = t[i-1]
        t[i-1] = temp
        i -= 1
print(t)


Editor is loading...