Doubly-linked list/Element definition: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: changed boxed comments.) |
m (→{{header|REXX}}: add/changed comments and whitespace.) |
||
Line 677: | Line 677: | ||
║ @del k,m ─── deletes the M items starting with item K. ║ |
║ @del k,m ─── deletes the M items starting with item K. ║ |
||
╚═════════════════════════════════════════════════════════════════════════╝ |
╚═════════════════════════════════════════════════════════════════════════╝ |
||
<lang rexx>/*REXX program |
<lang rexx>/*REXX program implements various List Manager functions (see the documentation above).*/ |
||
call sy 'initializing the list.' ; call @init |
call sy 'initializing the list.' ; call @init |
||
call sy 'building list: Was it a cat I saw'; call @put |
call sy 'building list: Was it a cat I saw' ; call @put "Was it a cat I saw" |
||
call sy 'displaying list size.' ; say |
call sy 'displaying list size.' ; say "list size="@size() |
||
call sy 'forward list' ; call @show |
call sy 'forward list' ; call @show |
||
call sy 'backward list' ; call @show ,,-1 |
call sy 'backward list' ; call @show ,,-1 |
||
call sy 'showing 4th item' ; call @show 4,1 |
call sy 'showing 4th item' ; call @show 4,1 |
||
call sy 'showing 5th & 6th items' ; call @show 5,2 |
call sy 'showing 5th & 6th items' ; call @show 5,2 |
||
call sy 'adding item before item 4: black' ; call @put |
call sy 'adding item before item 4: black' ; call @put "black",4 |
||
call sy 'showing list' ; call @show |
call sy 'showing list' ; call @show |
||
call sy 'adding to tail: there, in the ...'; call @put |
call sy 'adding to tail: there, in the ...' ; call @put "there, in the shadows, stalking its prey (and next meal)." |
||
call sy 'showing list' ; call @show |
call sy 'showing list' ; call @show |
||
call sy 'adding to head: Oy!' ; call @put |
call sy 'adding to head: Oy!' ; call @put "Oy!",0 |
||
call sy 'showing list' ; call @show |
call sy 'showing list' ; call @show |
||
exit /*stick a fork in it, we're done.*/ |
exit /*stick a fork in it, we're all done. */ |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
|||
/*──────────────────────────────────subroutines─────────────────────────*/ |
|||
p: return word(arg(1),1) |
p: return word(arg(1), 1) /*pick the first word out of many items*/ |
||
sy: say; say left('',30) "───" arg(1) '───'; return |
sy: say; say left('', 30) "───" arg(1) '───'; return |
||
⚫ | |||
@hasopt: arg o; return pos(o,opt)\==0 |
@hasopt: arg o; return pos(o, opt)\==0 |
||
@size: return $.# |
@size: return $.# |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
|||
@init: $.@=''; $.#=0; return 0 |
|||
⚫ | |||
⚫ | |||
⚫ | |||
$.@=_; call @adjust; return |
|||
@parms: arg opt |
|||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
|||
if @hasopt('k') then k=min($.#+1,max(1,p(k 1))) |
|||
@get: procedure expose $.; arg k,m,dir,_ |
|||
⚫ | |||
return |
|||
⚫ | |||
if dir==-1 & k=='' then k=$.# |
|||
m=p(m $.#); |
|||
call @parms 'kmd' |
call @parms 'kmd' |
||
⚫ | |||
say @get(k,m,dir); |
|||
⚫ | |||
return 0 |
|||
⚫ | |||
⚫ | |||
call @parms 'kmd' |
|||
⚫ | |||
⚫ | |||
⚫ | |||
return strip(_) |
return strip(_) |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
|||
@parms: arg opt /*define a variable based on an option.*/ |
|||
⚫ | |||
if @hasopt('k') then k=min($.#+1, max(1, p(k 1))) |
|||
if @hasopt('m') then m=p(m 1) |
|||
⚫ | |||
$.@=subword($.@,1,max(0,k-1)) x subword($.@,k) |
|||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
|||
call @adjust |
|||
⚫ | |||
return 0 |
|||
⚫ | |||
return |
|||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
|||
call @parms 'km' |
|||
⚫ | |||
⚫ | |||
m=p(m $.#); call @parms 'kmd'; say @get(k,m, dir); return</lang> |
|||
$.@=_ |
|||
call @adjust |
|||
return</lang> |
|||
'''output''' |
'''output''' |
||
<pre style="height:30ex"> |
<pre style="height:30ex"> |