ORDENAMIENTO PRAM CRCW
#Moreno Fonseca Luis Felipe
from threading import Thread
import math
#Definicion de Funciones
def hilo1(win,i):
win.insert(i,0)
def hilo2(win,i,j):
if(L[i]>L[j]):
win[i]=win[i]+1
else:
win[j]=win[j]+1
def hilo3(i,win):
L2.insert(win[i],L[i])
L2.pop(win[i]+1)
#Principal
L=[]
L2=[]
WIN=[]
indexMin=[]
print"\t-----Ordenamiento Pram CRCW-----"
n=int(raw_input("\nIngrese el Valor del Vector -> "))
i=0
while(i<n):
print "Teclea Valor -> ",i+1,":",
x=int(raw_input())
L.append(x)
L2.append(0)
i=i+1
n=len(L)
print "\nVector Original",L
i=1
while(i<=n):
t=Thread(target=hilo1,args=(WIN,i))
t.start()
t.join()
i=i+1
print "\nIinicializando win",WIN
i=0
while(i<=n):
j=i+1
while(j<n and i<j):
t=Thread(target=hilo2,args=(WIN,i,j))
t.start()
t.join()
j=j+1
i=i+1
print "\nLlenado WIN",WIN
i=0
while(i<n):
t=Thread(target=hilo3,args=(i,WIN))
t.start()
t.join()
i=i+1
print "\nVector Ordenado",L2
No hay comentarios:
Publicar un comentario