Anonymous user
Doubly-linked list/Traversal: Difference between revisions
m
→{{header|REXX}}: added whitespace, added DO-END comment label, indented DO loop. -- ~~~~
mNo edit summary |
m (→{{header|REXX}}: added whitespace, added DO-END comment label, indented DO loop. -- ~~~~) |
||
Line 846:
REXX doesn't have linked lists, as there are no pointers (or handles).
However, linked lists can be simulated with lists in REXX.
<lang rexx>/*REXX program that implements various List Manager functions. */
/*┌────────────────────────────────────────────────────────────────────┐
┌─┘ Functions of the List Manager └─┐
│ │
│ @init
│ │
│ @size
│ │
│ @show
│ @show k,1
│ @show k,m
│ @show ,,
│ │
│ @get k
│ @get k,m
│ │
│ @put x
│ @put x,0
│ @put x,k
│ │
│ @del k
│ @del k,m
└─┐ ┌─┘
└────────────────────────────────────────────────────────────────────┘*/
call sy 'initializing the list.'▼
▲ call sy 'initializing the list.'
call @init
call sy 'building list: Was it a cat I saw'
Line 899 ⟶ 896:
call sy 'showing list'
call @show
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────subroutines─────────────────────────*/
sy: say; say left('',30) "---" arg(1) '---'; return▼
p: return word(arg(1),1)
@hasopt: arg o; return pos(o,opt)\==0
@size: return $.#
Line 916 ⟶ 911:
return
@show: procedure expose $.; parse arg k,m,dir
if dir==-1 & k=='' then k=$.#
m=p(m $.#);
Line 923 ⟶ 918:
return 0
@get: procedure expose $.; arg k,m,dir,_
call @parms 'kmd'
do j=k for m by dir while j>0 & j<=$.#
_=_ subword($.@,j,1)
end /*j*/
return strip(_)
@put: procedure expose $.; parse arg x,k
k=p(k $.#+1)
call @parms 'k'
Line 937 ⟶ 932:
return 0
@del: procedure expose $.; arg k,m
call @parms 'km'
_=subword($.@,k,k-1) subword($.@,k+m)
$.@=_
call @adjust
return
</lang>
'''output'''
<pre style="height:50ex;overflow:scroll">
list size=6
Was it a cat I saw
saw I cat a it Was
cat
I saw
Was it a black cat I saw
Was it a black cat I saw there, in the shadows, stalking its prey (and next meal
Oy! Was it a black cat I saw there, in the shadows, stalking its prey (and next
</pre>
|