Priority queue: Difference between revisions

→‎version 1: added/changed whitespace and comments, simplified the program and output.
m (Added Sidef)
(→‎version 1: added/changed whitespace and comments, simplified the program and output.)
Line 3,574:
=={{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 pgmprogram implements a priority queue; with insert/show/delete top task.*/
numeric digits 100; #=0; @.= /*big #,; 0 tasks,; nullnullify priority queue.*/
say '══════ inserting tasks.'; call .ins 3 'Clear drains'
call .ins 4 'Feed cat'
Line 3,585:
call .ins 6 'Enjoy'
say '══════ showing tasks.'; call .show
say '══════ deletes top task.'; say .del() do # /*numberdelete ofthe taskstop task. */
exit /*stick a fork in sayit, .del() we're all /*delete top taskdone. */
/*────────────────────────────────────────────────────────────────────────────*/
end /* [↑] do top first.*/
.topdel: procedure expose @. #; parse top=arg p; top# if p=='' then p=.top()
exit /*stick a fork in it, we're done.*/
x=@.p; @.p= /*delete the top task entry. end /* [↑] do top first.*/
/*──────────────────────────────────.INS subroutine─────────────────────*/
exit return x /*stickreturn athe forktask inthat it,was we'rejust done.deleted*/
.ins: procedure expose @. #; #=#+1; @.#=arg(1); return # /*entry,P,task.*/
/*────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────.DEL subroutine─────────────────────*/
.delins: procedure expose @. #; #=#+1; parse @.#=arg p(1); return # if p=='' then p=/*entry,P,task.top()*/
/*────────────────────────────────────────────────────────────────────────────*/
x=@.p; @.p= /*delete the top task entry. */
return x /*return task that was deleted. */
/*──────────────────────────────────.SHOW subroutine────────────────────*/
.show: procedure expose @. #
do j=1 for #; _=@.j; if _=='' then iterate; say _; end
return end /*j*/ /* [↑] show whole list or just 1one. */
/*────────────────────────────────────────────────────────────────────────────*/
return
.instop: procedure expose @. #; #=#+1; @.# top=arg(1); return # /*entry,P,task.*/ top#=
/*──────────────────────────────────.TOP subroutine─────────────────────*/
do j=1 for #; _=word(@.j,1); if _=='' then iterate
.top: procedure expose @. #; top=; top#=
do jif top=1='' | for_>top # then do; _ top=word(@.j,1)_; if _top#==''j; then iterateend
if top==''end | _>top then do; top=_; top#=/*j; end*/
return end /*j*top#</lang>
return top#</lang>
'''output'''
<pre>
Line 3,619 ⟶ 3,616:
══════ deletes top task.
6 Relax
6 Enjoy
5 Make tea
4 Feed cat
3 Clear drains
2 Tax return
1 Solve RC tasks
</pre>