RosettaCodeData/Task/Priority-queue/REXX/priority-queue-1.rexx

23 lines
1.9 KiB
Rexx
Raw Permalink Normal View History

2018-06-22 20:57:24 +00:00
/*REXX program implements a priority queue with insert/display/delete the top task.*/
#=0; @.= /*0 tasks; nullify the priority queue.*/
2016-12-05 22:15:40 +01:00
say ' inserting tasks.'; call .ins 3 "Clear drains"
call .ins 4 "Feed cat"
call .ins 5 "Make tea"
call .ins 1 "Solve RC tasks"
call .ins 2 "Tax return"
call .ins 6 "Relax"
call .ins 6 "Enjoy"
2014-01-17 05:32:22 +00:00
say ' showing tasks.'; call .show
2016-12-05 22:15:40 +01:00
say ' deletes top task.'; say .del() /*delete the top task. */
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
2018-06-22 20:57:24 +00:00
.del: procedure expose @. #; arg p; if p='' then p=.top(); y=@.p; @.p=; return y
2016-12-05 22:15:40 +01:00
.ins: procedure expose @. #; #=#+1; @.#=arg(1); return # /*entry, P, task.*/
2018-06-22 20:57:24 +00:00
.show: procedure expose @. #; do j=1 for #; _=@.j; if _\=='' then say _; end; return
2016-12-05 22:15:40 +01:00
/*──────────────────────────────────────────────────────────────────────────────────────*/
.top: procedure expose @. #; top=; top#=
2018-06-22 20:57:24 +00:00
do j=1 for #; _=word(@.j, 1); if _=='' then iterate
if top=='' | _>top then do; top=_; top#=j; end
2016-12-05 22:15:40 +01:00
end /*j*/
return top#