Anonymous user
Doubly-linked list/Element insertion: Difference between revisions
Doubly-linked list/Element insertion (view source)
Revision as of 20:34, 17 October 2012
, 11 years ago→{{header|REXX}}: changed the style of the output. -- ~~~~
mNo edit summary |
m (→{{header|REXX}}: changed the style of the output. -- ~~~~) |
||
Line 724:
=={{header|REXX}}==
REXX doesn't have linked lists, as there are no pointers (or handles).
<br>However, linked lists can be simulated with lists in REXX.▼
<lang rexx>/*REXX program that implements various List Manager functions. */▼
▲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 @init
call sy 'building list: Was it a cat I saw'; call @put 'Was it a cat I saw'
call sy 'displaying list size.' ;
call sy 'backward list'
call sy 'showing 4th item' ; call @show 4,1
call sy 'showing 6th & 6th items'
call sy 'showing list'
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 sy 'adding to head: Oy!' ; call @put 'Oy!',0
call sy 'showing list'
/*──────────────────────────────────subroutines─────────────────────────*/
▲ call sy 'adding item before item 4: black'
▲ call sy 'showing list'
▲ call sy 'adding to tail: there, in the ...'
▲call @put 'there, in the shadows, stalking its prey (and next meal).'
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 796 ⟶ 777:
return
@show: procedure expose $.; parse arg k,m,dir
if dir==-1 & k=='' then k=$.#
m=p(m $.#);
Line 803 ⟶ 784:
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 817 ⟶ 798:
return 0
@del: procedure expose $.; arg k,m
call @parms 'km'
_=subword($.@,k,k-1) subword($.@,k+m)
Line 823 ⟶ 804:
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 meal).
</pre>
|