Priority queue: Difference between revisions

m
m (→‎{{header|Quackery}}: rethought insert)
m (→‎{{header|Quackery}}: added remove)
Line 5,449:
<lang Quackery>( ***** priotity queue ***** )
 
[ stack ] is heap.pq ( [ --> [ )
 
[ stack ] is comp.pq ( [ --> [ )
 
[ unpack
comp.pq put heap.pq put ] is pq->stacks ( [ --> )
 
[ heap.pq take comp.pq take
2 pack ] is stacks->pq ( --> [ )
 
[ heap.pq share swap peek ] is heapeek ( n --> x )
 
[ heap.pq take
swap poke heap.pq put ] is heapoke ( n x --> )
 
[ 1+ 2 / 1 - ] is parent ( n --> n )
 
[ 0 > ] is has-parent ( n --> b )
 
[ 2 * 1+ ] is child ( n --> n )
 
[ child heap.pq share size < ] is has-child ( n --> b )
 
[ 1+ ] is sibling ( n --> n )
 
[ sibling
heap.pq share size < ] is has-sibling ( n --> b )
 
[ comp.pq share do ] is compare ( x x --> b )
 
[ 0 peek size ] is pqsize ( p --> b )
 
[ swap pq->stacks
Line 5,492:
rot 2drop swap ]
heapoke
stacks->pq ] is topq ( p x --> p )
 
[ dup heapeek swap
Line 5,506:
again
2drop ]
heapoke ] is heapify.pq ( n --> )
 
[ dup pqsize 0 = if
Line 5,519:
swap join heap.pq put
0 heapify.pq ]
stacks->pq swap ] is frompq ( p --> p x )
 
[ ]'[ 2 pack pq->stacks
Line 5,525:
size 2 / times
[ i heapify.pq ]
stacks->pq ] is pqwith ( [ --> p )
 
( ***** task ***** )
 
[ 2 pack topq ] is insert ( p n $ --> p )
 
[ frompq unpack ] is remove ( p --> p n $ )
[] pqwith [ 0 peek swap 0 peek > ]
 
[] pqwith [ 0 peek swapdip [ 0 peek >] < ]
 
3 $ "Clear drains" insert
Line 5,539 ⟶ 5,541:
2 $ "Tax return" insert
 
5 times [ frompq unpack
[ remove
swap echo say ": "
swap echo say ": echo$ cr ]"
echo$ cr ]
drop</lang>
 
1,493

edits