martes, 21 de abril de 2015

Ordenamiento PRAM EREW Recursivo con Merge Secuencial------- Código en Python

Universidad Autónoma del Estado de México
Facultad de Ingeniería
Ingeniería en Computación
Ordenamiento PRAM EREW Recursivo con Merge Secuencial-----Código en Python

Profesor: Ing Elfego Gutierrez Ocampo
Alumno: Eduardo Manuel Flores Vera






#Flores Vera Eduardo Manuel
import os


#Definicion de Funciones
def mergeSort(alist):
    print("DIVIDIENDO ",alist)
    if len(alist)>1:
        mid = len(alist)//2
        lefthalf = alist[:mid]
        righthalf = alist[mid:]

        mergeSort(lefthalf)
        mergeSort(righthalf)

        i=0
        j=0
        k=0
        while i<len(lefthalf) and j<len(righthalf):
            if lefthalf[i]<righthalf[j]:
                alist[k]=lefthalf[i]
                i=i+1
            else:
                alist[k]=righthalf[j]
                j=j+1
            k=k+1

        while i<len(lefthalf):
            alist[k]=lefthalf[i]
            i=i+1
            k=k+1

        while j<len(righthalf):
            alist[k]=righthalf[j]
            j=j+1
            k=k+1
    print("UNIENDO ",alist)

#Programa Principal
alist = []
x=int(raw_input("INGRESE EL NUMERO DE VALORES A INGRESAR"))
i=1
while (i<=x):
    n=int(raw_input("INGRESE UN VALOR"))
    alist.append(n)
    i=i+1
             
   
print 'VALORES ORDENADOS:'
print(alist)

os.system('pause')

No hay comentarios.:

Publicar un comentario