Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.98 KB | None | 0 0
  1. def tri_comptage(liste):
  2.    
  3.     #on trouve d'abord le max et le min de la liste
  4.     maximum = liste[0]
  5.     minimum = liste[0]
  6.     for j in range(len(liste)):
  7.         if liste[j] > maximum:
  8.             maximum = liste[j]
  9.         elif liste[j] < minimum:
  10.             minimum = liste[j]
  11.            
  12.     #on cree la liste pour compter le nombre d'occurrences de valeurs
  13.     liste_comptage = []
  14.     for i in range(0, maximum):
  15.         liste_comptage += [i]
  16.         liste_comptage[i] = 0
  17.  
  18.     #remplissage de la liste d'occurrences de valeurs
  19.    
  20.     for k in range(len(liste)):
  21.         liste_comptage[liste[k] - minimum] = liste_comptage[liste[k] - minimum] + 1
  22.  
  23.     #transfert de la liste d'occurrences a la liste de valeurs
  24.     indice = 0
  25.     for l in range(len(liste_comptage)):
  26.         while liste_comptage[l] > 0:
  27.             liste[indice] = l + minimum
  28.             indice += 1
  29.             liste_comptage[l] -= 1
  30.     return liste
  31. print(tri_comptage([1, 15, 20, 16, 2]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement