Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,35 @@
|
|||
DIM test(9)
|
||||
test() = 4, 65, 2, -31, 0, 99, 2, 83, 782, 1
|
||||
PROCheapsort(test())
|
||||
FOR i% = 0 TO 9
|
||||
PRINT test(i%) ;
|
||||
NEXT
|
||||
PRINT
|
||||
END
|
||||
|
||||
DEF PROCheapsort(a())
|
||||
LOCAL e%
|
||||
PROCheapify(a())
|
||||
FOR e% = DIM(a(),1) TO 1 STEP -1
|
||||
SWAP a(e%), a(0)
|
||||
PROCsiftdown(a(), 0, e%-1)
|
||||
NEXT
|
||||
ENDPROC
|
||||
|
||||
DEF PROCheapify(a())
|
||||
LOCAL s%, m%
|
||||
m% = DIM(a(),1)
|
||||
FOR s% = (m% - 1) / 2 TO 0 STEP -1
|
||||
PROCsiftdown(a(), s%, m%)
|
||||
NEXT
|
||||
ENDPROC
|
||||
|
||||
DEF PROCsiftdown(a(), s%, e%)
|
||||
LOCAL c%, r%
|
||||
r% = s%
|
||||
WHILE r% * 2 + 1 <= e%
|
||||
c% = r% * 2 + 1
|
||||
IF c% + 1 <= e% IF a(c%) < a(c% + 1) c% += 1
|
||||
IF a(r%) < a(c%) SWAP a(r%), a(c%) : r% = c% ELSE ENDPROC
|
||||
ENDWHILE
|
||||
ENDPROC
|
||||
Loading…
Add table
Add a link
Reference in a new issue