Insertsort
#Hernandez Gutierrez Erik
#Insertsort
import os
import math
#Definicion de Funciones
def insertion_sort(a):
for i in range(1, len(a)):
v = a[i]
j = i
while a[j-1] > v and j>=1:
a[j] = a[j-1]
j -= 1
a[j] = v
return a
#Programa Principal
print "=======================INSERTSORT=================="
a=[]
x=int(raw_input("INGRESE EL NUMERO DE DATOS A INGRESAR EN EL VECTOR:"))
i=1
while (i<=x):
n=int(raw_input("INGRESE DATO:"))
a.append(n)
i+=1
a=insertion_sort(a)
print "SU LISTA ORDENADA CON EL METODO INSERTSORT ES:", a
os.system('pause')
#Insertsort
import os
import math
#Definicion de Funciones
def insertion_sort(a):
for i in range(1, len(a)):
v = a[i]
j = i
while a[j-1] > v and j>=1:
a[j] = a[j-1]
j -= 1
a[j] = v
return a
#Programa Principal
print "=======================INSERTSORT=================="
a=[]
x=int(raw_input("INGRESE EL NUMERO DE DATOS A INGRESAR EN EL VECTOR:"))
i=1
while (i<=x):
n=int(raw_input("INGRESE DATO:"))
a.append(n)
i+=1
a=insertion_sort(a)
print "SU LISTA ORDENADA CON EL METODO INSERTSORT ES:", a
os.system('pause')
Comentarios
Publicar un comentario