Created
November 28, 2014 09:18
-
-
Save pbondoer/a1f35a32d3bcd3d2c8d4 to your computer and use it in GitHub Desktop.
Tri par selection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from random import randint | |
def selection(liste, debut = 0): | |
minimum = debut | |
for i in range(debut, len(liste)): | |
if(liste[i] < liste[minimum]): | |
minimum = i | |
if(minimum != debut): | |
liste[minimum], liste[debut] = liste[debut], liste[minimum] | |
print(debut, ">>>", liste) #case test | |
if(debut < len(liste) - 1): | |
selection(liste, debut + 1) | |
#test | |
def input_liste(): | |
liste = [] | |
alea = input("Voulez vous générer une liste aléatoire (O/N)? ") | |
if(alea.lower() == "o"): | |
length = int(input("Combien de nombres? ")) | |
mini = int(input("Extreme 1? ")) | |
maxi = int(input("Extreme 2? ")) | |
for i in range(0, length): | |
n = randint(mini, maxi) #utiliser uniform pour float | |
liste.append(n) | |
elif(alea.lower() == "n"): | |
length = int(input("Combien de nombres? ")) | |
for i in range(0, length): | |
n = int(input("liste[" + str(i) + "] = ")) | |
liste.append(n) | |
else: | |
print("Valeur incorrecte") | |
raise SystemExit(0) | |
return liste | |
liste = input_liste() | |
print("...") | |
print(liste) | |
print("...") | |
selection(liste) | |
print("...") | |
print(liste) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment