2018-11-22 20:02:30 -03:00
|
|
|
entrada: array: arreglo de n datos; n: tamaño del arreglo
|
2018-11-21 18:25:34 -03:00
|
|
|
salida: arreglo ordenado
|
|
|
|
|
2018-11-22 20:02:30 -03:00
|
|
|
funcion ordenamientobitonico(array, n)
|
|
|
|
orden(array, n, 1)
|
|
|
|
return array
|
2018-11-21 18:25:34 -03:00
|
|
|
fin funcion
|
|
|
|
|
2018-11-22 20:02:30 -03:00
|
|
|
funcion potencia_de_dos(n)
|
|
|
|
si n = 0 entonces
|
|
|
|
retornar 0
|
|
|
|
fin si
|
|
|
|
mientras n distinto 1 hacer
|
|
|
|
si n es modulo de 2 entonces
|
|
|
|
retornar 0
|
|
|
|
fin si
|
|
|
|
fin mientras
|
|
|
|
retornar 1
|
|
|
|
fin funcion
|
2018-11-21 18:25:34 -03:00
|
|
|
|
2018-11-22 20:02:30 -03:00
|
|
|
funcion mejor_potencia_de_2_menos_a_n(n)
|
|
|
|
k = 1
|
|
|
|
mientras k > 0 y k < n hacer
|
2018-11-21 18:25:34 -03:00
|
|
|
busca el numero potencia de dos mas proximo hacia abajo en n
|
2018-11-22 20:02:30 -03:00
|
|
|
fin mientras
|
|
|
|
retorna k
|
2018-11-21 18:25:34 -03:00
|
|
|
fin funcion
|
|
|
|
|
2018-11-22 20:02:30 -03:00
|
|
|
funcion comparar(i, j, dir, array)
|
|
|
|
temp = array[i]
|
|
|
|
array[i] = array[j]
|
|
|
|
array[j] = temp
|
2018-11-21 18:25:34 -03:00
|
|
|
fin funcion
|
|
|
|
|
2018-11-22 20:02:30 -03:00
|
|
|
funcion unionbitonica(low, n, dir, array)
|
|
|
|
si n > 1 entonces
|
|
|
|
k = n / 2
|
|
|
|
para i = low hasta i < low + k con paso i = i + 1
|
|
|
|
comparar(i + k, di, array)
|
|
|
|
fin para
|
|
|
|
unionbitonica(low, k, dir, array)
|
|
|
|
unionbitonica(low + k, k, dir, array)
|
|
|
|
fin si
|
2018-11-21 18:25:34 -03:00
|
|
|
fin funcion
|
|
|
|
|
2018-11-22 20:02:30 -03:00
|
|
|
funcion unionbitonico2(low, n, dir, array)
|
|
|
|
si n > 1 entonces
|
|
|
|
k = mejor_potencia_de_2_menos_a_n
|
|
|
|
para i = low hasta i < low + n - k con paso i = i + 1 hacer
|
|
|
|
comparar(i, i + k, dir, array)
|
|
|
|
fin para
|
|
|
|
ordenamientobitonico2(low, k, dir, array)
|
|
|
|
ordenamientobitonico2(low + k, n - k, dir, array)
|
2018-11-21 18:25:34 -03:00
|
|
|
fin funcion
|
|
|
|
|
2018-11-22 20:02:30 -03:00
|
|
|
funcion recorrerbitonico(low, n, dir, array)
|
|
|
|
si n > 1 entonces
|
|
|
|
k = n / 2
|
|
|
|
recorrerbitonico(low, k, 1, array)
|
|
|
|
recorrerbitonico(low + k, k, 0, array)
|
|
|
|
unionbitonica(low, n, dir, array)
|
|
|
|
fin si
|
2018-11-21 18:25:34 -03:00
|
|
|
fin funcion
|
|
|
|
|
2018-11-22 20:02:30 -03:00
|
|
|
funcion recorrerbitonico2(low, n, dir, array)
|
|
|
|
si n > 1 entonces
|
|
|
|
k = n / 2
|
|
|
|
recorrerbitonico2(low, k, !di, array)
|
|
|
|
recorrerbitonico2(low + k, n - k, dir, array)
|
|
|
|
unionbitonico2(low, n, dir, array)
|
|
|
|
fin si
|
2018-11-21 18:25:34 -03:00
|
|
|
fin funcion
|
|
|
|
|
2018-11-22 20:02:30 -03:00
|
|
|
funcion orden(array, n, dir)
|
|
|
|
si potencia_de_dos(n) entonces
|
|
|
|
recorrerbitonico(0, n, dir, array)
|
|
|
|
fin si
|
|
|
|
sino
|
|
|
|
recorrerbitonico2(0, n, dir, array)
|
|
|
|
fin sino
|
2018-11-21 18:25:34 -03:00
|
|
|
fin funcion
|