Heaps are a data structure used to implement priority queues. I'm not sure yet what that means, but whatever.
This routine from tibasicdev adds an element to a max-heap stored in L1, where the top node is L1(1) and children are 2I and 2I+1.
Code:
The following (untested and very unoptimized) snippet *probably* removes the top element from a max-heap.
Code:
Will update with better code.
This routine from tibasicdev adds an element to a max-heap stored in L1, where the top node is L1(1) and children are 2I and 2I+1.
Code:
1+dim(L1->I
N->L1(I
While N>L1(max(1,int(I.5
int(I.5->J
L1(J->L1(I
N->L1(J
J->I
End
The following (untested and very unoptimized) snippet *probably* removes the top element from a max-heap.
Code:
L1(dim(L1->N
dim(L1)-1->dim(L1
1->I
While I2<dim(L1) and Ans
If N<max(L1(2I),L1(2I+1
Then
L1(2I+(L1(2I)<L1(2I+1->L1(I
1
Else
N->L1(I
0
End
End
Will update with better code.