sábado, 16 de mayo de 2015

Algoritmo # 6


Ordemaniento PRAM EREW  Secuencial


#Moreno Fonseca Luis Felipe
import os


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("Ingresa el total de valores -> "))
i=1
while (i<=x):
    n=int(raw_input("Ingresa Numero"))
    alist.append(n)
    i=i+1
               
      
print 'Numeros Ordenados'
print(alist)

No hay comentarios:

Publicar un comentario