Priority queue: Difference between revisions
m
→Using ordered list (plus merge function)
Line 4,779:
flush
// subs can read from module's stack
println(
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(
PeekTop(zz) // Solve RC tasks#2
println(
merge(pq, zz, false)
println("Peek top from pq queue")
Line 4,798:
PopOne(pq)
end while
println(
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
k$= eval$(kqp!)
if not exist(pq, eval$(kqp!)) then
Line 4,825:
needsort=true
else
end if
stack p {
if emptyqueue then
|