Priority queue: Difference between revisions

m
Line 4,779:
flush
// subs can read from module's stack
println( "Add items to pq queue")
Data 4 ,"Feed cat",5 , "Make tea", 3, "Clear drains",1 , "Solve RC tasks"
AddItems(pq)
println("Add items to zz queue")
AddItems(zz, 2 , "Tax return", 1 ,"Solve RC tasks#2")
println( "Peek top from zz queue")
PeekTop(zz) // Solve RC tasks#2
println( "Merge two priority lists")
merge(pq, zz, false)
println("Peek top from pq queue")
Line 4,798:
PopOne(pq)
end while
println( "Pop one from zz until empty queue")
while len(zz)>0
PopOne(zz)
Line 4,816:
sub merge(pq, qp, emptyqueue)
local needsort=false
local kqp=each(qp, -1, 1), k$, t, p
while kqp
local t=eval(kqp)
k$= eval$(kqp!)
if not exist(pq, eval$(kqp!)) then
Line 4,825:
needsort=true
else
local p=eval(pq)
end if
stack p {
if emptyqueue then
404

edits