Jump to content

Priority queue: Difference between revisions

m
→‎version 1: added/changed comments, indentations, and whitespace.
(Added Elixir)
m (→‎version 1: added/changed comments, indentations, and whitespace.)
Line 3,591:
=={{header|REXX}}==
===version 1===
Programming note:   this REXX version allows any number (with or without decimals, say, 5.7) for the priority, including negative numbers.   The priority number can be up to one hundred digits.
<lang rexx>/*REXX program implements a priority queue; with insert/showdisplay/delete the top task. */
numeric digits 100; #=0; @.= /*big #; /*0 tasks; nullify the priority queue.*/
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'"
say '══════ showing tasks.'; call .show
say '══════ deletes top task.'; say .del() /*delete the top task. */
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*────────────────────────────────────────────────────────────────────────────*/
.del: procedure expose @. #; parse arg p; if p=='' then p=.top(); x=@.p; @.p=; return x
x=@.p; @.p= /*delete the top task entry. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
return x /*return the task that was just deleted*/
.ins: procedure expose @. #; #=#+1; @.#=arg(1); return # /*entry, P, task.*/
/*────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
.ins: procedure expose @. #; #=#+1; @.#=arg(1); return # /*entry,P,task.*/
.show: procedure expose @. #; do j=1 for #; _=@.j; if _=='' then iterate; say _; end
/*────────────────────────────────────────────────────────────────────────────*/
return x /*return the[↑] task thatshow waswhole list or just deletedone. */
.show: procedure expose @. #
/*──────────────────────────────────────────────────────────────────────────────────────*/
do j=1 for #; _=@.j; if _=='' then iterate; say _; end
return /* [↑] show whole list or just one. */
/*────────────────────────────────────────────────────────────────────────────*/
.top: procedure expose @. #; top=; top#=
do j=1 for #; _=word(@.j,1); if _=='' then iterate
Cookies help us deliver our services. By using our services, you agree to our use of cookies.