You are on page 1of 2

def fusion(l1,l2):

if not l1:return l2
if not l2:return l1
if l1[0]<=l2[0]:return [l1[0]] +fusion(l1[1:],l2)
else:return [l2[0]]+ fusion(l1,l2[1:])
def tri_fusion(l):
if len(l)<=1:return l
m=len(l)//2
droite=l[m:]
gauche=l[:m]
droite=tri_fusion(droite)
gauche=tri_fusion(gauche)
return fusion(gauche,droite)
#print(tri_fusion([9,4,2,1,0]))

def rapide(l):
if len(l)<=1:return l
pivot=l[-1]
gauche=[x for x in l if x < pivot]
milieu=[x for x in l if x==pivot]
droite=[x for x in l if x > pivot]
return rapide(gauche)+milieu+rapide(droite)
#print(rapide([9,4,2,1,0,18,10,9]))
def bulle(l):
n=len(l)
not_sorted=True
k=0
while not_sorted:
not_sorted=False
for i in range(1,n-k):
if l[i]<l[i-1]:
l[i],l[i-1]=l[i-1],l[i]
not_sorted=True
k+=1
return l
#print(bulle([9,4,2,1,0,18,10,9]))
def selection(l):
n=len(l)
for i in range(n):
indx=i
for j in range(i+1,n):
if l[j]<l[indx]:
indx=j
l[i],l[indx]=l[indx],l[i]
return l
#print(selection([9,4,2,1,0,18,10,9]))
def tri_insertion(arr):
for i in range(1, len(arr)):
cle = arr[i]
j = i - 1
while j >= 0 and cle < arr[j]:
arr[j + 1] = arr[j]
j -= 1
arr[j + 1] = cle
l=[9,4,2,1,0,18,10,9]
def insertion(l):
n=len(l)
for i in range(1,n):
cle=l[i]
j=i-1
while j>=0 and cle<l[j]:
l[j+1]=l[j]
j=j-1
l[j+1]=cle
return l
print(insertion(l))

You might also like