Singly-linked list/Element insertion: Difference between revisions
Content added Content deleted
(→{{header|jq}}: def insert($x):) |
Walterpachl (talk | contribs) (→{{header|ooRexx}}: corrected linkedlist to list and added output) |
||
Line 1,654: | Line 1,654: | ||
See [[Singly-linked_list/Element_definition#ooRexx|Single-linked list/Element definition]] for full class definition. |
See [[Singly-linked_list/Element_definition#ooRexx|Single-linked list/Element definition]] for full class definition. |
||
<syntaxhighlight lang="oorexx"> |
<syntaxhighlight lang="oorexx"> |
||
list = . |
list = .list~new |
||
index = list~insert("abc") -- insert a first item, keeping the index |
index = list~insert("abc") -- insert a first item, keeping the index |
||
Call show |
|||
list~insert("def") -- adds to the end |
list~insert("def") -- adds to the end |
||
Call show |
|||
list~insert("123", .nil) -- adds to the begining |
list~insert("123", .nil) -- adds to the begining |
||
Call show |
|||
list~insert("456", index) -- inserts between "abc" and "def" |
list~insert("456", index) -- inserts between "abc" and "def" |
||
Call show |
|||
list~remove(index) -- removes "abc" |
list~remove(index) -- removes "abc" |
||
Call show |
|||
⚫ | |||
exit |
|||
show: |
|||
s='' |
|||
Do x over list |
|||
s=s x |
|||
end |
|||
say s |
|||
⚫ | |||
{{out]] |
|||
<pre> abc |
|||
abc def |
|||
123 abc def |
|||
123 abc 456 def |
|||
123 456 def |
|||
</pre> |
|||
=={{header|Pascal}}== |
=={{header|Pascal}}== |