import numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation import matplotlib.colors as colors import time def p(e): print(e) return e def alealiste(n,M): return np.array(np.random.random((n,))*M,dtype=int) def ytrinsertion(L): if len(L)<=1: return L out = np.empty((len(L),),dtype=int) out[0] = L[0] out[1:] = yield from ytrinsertion(L[1:]) for i in range(len(out)-1): if out[i+1]>=L[0]: out[i]=L[0] return out out[i] = out[i+1] out[i+1] = L[0] yield out out[-1]=L[0] yield out def triRapideEnPlace(l,a=None,b=None): """ Trie la liste l entre a et b """ if a==None: a = 0 if b==None: b = len(l) if b-a==0: return l if b-a==1: return l n = a+(b-a)//2 pivot = l[n] i = n maxindex = b minindex = a while maxindex != minindex: # On souhaite ranger l'élément i dans la bonne moitié # On suppose que i n'est pas dans les parties rangées if l[i] < pivot or (l[i]==pivot and np.random.randint(0,2)==1): l[i],l[minindex] = l[minindex],l[i] minindex += 1 else: l[i],l[maxindex-1] = l[maxindex-1],l[i] maxindex -= 1 yield l # On prend un i pas dans les parties triées i = (maxindex-minindex)//2 + minindex yield from triRapideEnPlace(l,a,maxindex) yield from triRapideEnPlace(l,maxindex,b) def triFusionRec(l,index): if len(l)==0: return l if len(l)==1: return l n = len(l)//2 l1,l2 = triFusionRec(l[:n],0),triFusionRec(l[n:],n) out = [] i,j = 0,0 while i=len(l2) or (i