Priority queue: Difference between revisions

Content added Content deleted
(Added Quackery.)
Line 5,210: Line 5,210:
The task [[Sorting algorithms/Heapsort#Quackery]] implements a priority queue. Here we reuse the words <code>comparison</code>, <code>toheap</code>, and <code>fromheap</code> from that task and adapt them to this task. <code>p</code> in the stack comments denotes a priority queue.
The task [[Sorting algorithms/Heapsort#Quackery]] implements a priority queue. Here we reuse the words <code>comparison</code>, <code>toheap</code>, and <code>fromheap</code> from that task and adapt them to this task. <code>p</code> in the stack comments denotes a priority queue.


<lang Quackery> [ ' [ 0 peek swap
<lang Quackery>
0 peek > ]
[ ' [ 0 peek swap 0 peek > ]
comparison put
comparison put [] ] is new-pq ( --> p )
[] ] is new-pq ( --> p )


[ nested join toheap ] is insert ( p n $ --> p )
[ nested join toheap ] is insert ( p n $ --> p )


[ fromheap 1 peek ] is remove ( p --> p $ )
[ fromheap 1 peek ] is remove ( p --> p $ )


[ drop comparison release ] is end-pq ( p --> )
[ drop comparison release ] is end-pq ( p --> )


new-pq
new-pq