mercredi 29 octobre 2014

not expected bubble sort issue in python


Vote count:

0




I have a problem with this code, bubble sort is not working properly.



numero = raw_input('Ingrese los numeros a ordenar:')
numeros = []

while numero != '': #hit enter to finish the number input
numeros.append(numero)
numero = raw_input()

def burbuja(temporal):
tamanio = len(temporal) -1
ordenado = False
while not ordenado:
ordenado = True
for i in range(tamanio):
if temporal[i] > temporal[i+1]:
ordenado = False
temporal[i], temporal[i+1] = temporal[i+1], temporal[i]

burbuja(numeros)
print 'Los numeros ordenados son:', numeros


The problem is when I insert numbers like this



'22', '13, '2', '4'


My expected result is



'2', '4', '13', '22'


But I get:



'13', '2' ,'22', '4'


I hope you can help me to resolve my problem


Thank you :)



asked 28 secs ago







not expected bubble sort issue in python

Aucun commentaire:

Enregistrer un commentaire