-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lab04Ejercicio1.py
83 lines (63 loc) · 1.51 KB
/
Lab04Ejercicio1.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# Importando los modulos necesarios
from time import time
import random
from math import log10
# Iniciando los datos
#a = [] # Arreglo donde se guardarán los elementos a ordenar
#ordenado = [] # Arreglo final ya ordenado
#c = [] # Arreglo donde se guardarán los ceros que cuentan los elementos de otro Arreglo
#contador =
#for i in range()
A = [10,5,5,4,4,6,3,7,7,4,15,0]
B = []
"""
def CountingSort(A, B):
k = max(A)
C=[]
for i in range(len(A)):
B.append(0)
for i in range(0,k+1):
C.append(0)
for j in range(len(A)):
C[A[j]] = C[A[j]] + 1
print(C)
print("\n")
for i in range(k):
if i == 0 :
C[i] = C[i] + C[i-1]
#print(C)
try:
for j in range(len(A)-1,0,-1):
B[C[A[j]]] = A[j]
C[A[j]] = C[A[j]] - 1
except:
pass
#print(C)
return B
a = CountingSort(A, B)
print(a)
print (B)
"""
def Insercion(arreglo,d):
n = 1
maximo = max
while n != len(arreglo):
k = n
while k != 0 and (((arreglo[k-1] // (10 ** d)) % 10) <= (((arreglo[k] // (10 ** d)) % 10))):
arreglo[k-1],arreglo[k] = arreglo[k], arreglo[k-1]
k = k - 1
n = n + 1
print (arreglo)
print("\n")
return arreglo
for i in range(5):
def RadixSort (A):
d = int(log10(max(A)) // 1)
for i in (0,d+1):
A = Insercion(A,i)
return A
paja = [9602,7540,959,8000,7596,841,7534,7931,3437,6871]
paja = RadixSort(paja)
# Postcondicion
#assert(all(paja[i] <= paja[i+1] for i in range(len(paja)-1)))
print(paja)