-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHeapSort.py
More file actions
32 lines (28 loc) · 749 Bytes
/
HeapSort.py
File metadata and controls
32 lines (28 loc) · 749 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import time
def heapsort(lista,tam):
tiempo = time.time()
for k in range(tam-1,-1,-1):
for i in range(0,k):
item=lista[i]
j=(i+1)/2
while j>=0 and lista[j]<item:
lista[i]=lista[j]
i=j
j=j/2
lista[i]=item;
temp=lista[0];
lista[0]=lista[k];
lista[k]=temp;
def imprimeLista(lista,tam):
for i in range(0,tam):
print lista[i]
print time.time()-tiempo
def leeLista():
lista=[]
cn=int(raw_input("Cantidad de numeros a ingresar: "))
for i in range(0,cn):
lista.append(int(raw_input("Ingrese numero %d : " % i)))
return lista
A=leeLista()
heapsort(A,len(A))
imprimeLista(A,len(A))