Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,74 @@
!creamos la matriz y la inicializamos
LET lim = 20
DIM array(20)
FOR i = 1 TO lim
LET array(i) = INT(RND * 100) + 1
NEXT i
SUB printArray (lim)
FOR i = 1 TO lim
!PRINT using("###", array(i));
PRINT array(i); " ";
NEXT i
PRINT
END SUB
SUB heapify (count)
LET start = INT(count / 2)
DO WHILE start >= 1
CALL siftDown (start, count)
LET start = start - 1
LOOP
END SUB
SUB siftDown (inicio, final)
LET root = inicio
DO WHILE root * 2 <= final
LET child = root * 2
LET SWAP = root
IF array(SWAP) < array(child) THEN
LET SWAP = child
END IF
IF child+1 <= final THEN
IF array(SWAP) < array(child+1) THEN
LET SWAP = child + 1
END IF
END IF
IF SWAP <> root THEN
CALL SWAP (root, SWAP)
LET root = SWAP
ELSE
EXIT SUB
END IF
LOOP
END SUB
SUB SWAP (x,y)
LET tmp = array(x)
LET array(x) = array(y)
LET array(y) = tmp
END SUB
SUB heapSort (count)
CALL heapify (count)
PRINT "el montículo:"
CALL printArray (count)
LET final = count
DO WHILE final > 1
CALL SWAP (final, 1)
CALL siftDown (1, final-1)
LET final = final - 1
LOOP
END SUB
!--------------------------
PRINT "Antes de ordenar:"
CALL printArray (lim)
PRINT
CALL heapSort (lim)
PRINT
PRINT "Despues de ordenar:"
CALL printArray (lim)
END