Doubly-linked list/Element removal: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
|||
Line 10: | Line 10: | ||
The user must type in the monitor the following command after compilation and before running the program!<pre>SET EndProg=*</pre> |
The user must type in the monitor the following command after compilation and before running the program!<pre>SET EndProg=*</pre> |
||
{{libheader|Action! Tool Kit}} |
{{libheader|Action! Tool Kit}} |
||
< |
<syntaxhighlight lang="action!">CARD EndProg ;required for ALLOCATE.ACT |
||
INCLUDE "D2:ALLOCATE.ACT" ;from the Action! Tool Kit. You must type 'SET EndProg=*' from the monitor after compiling, but before running this program! |
INCLUDE "D2:ALLOCATE.ACT" ;from the Action! Tool Kit. You must type 'SET EndProg=*' from the monitor after compiling, but before running this program! |
||
Line 98: | Line 98: | ||
TestRemove(listEnd) |
TestRemove(listEnd) |
||
TestRemove(listBegin) |
TestRemove(listBegin) |
||
RETURN</ |
RETURN</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Doubly-linked_list_element_removal.png Screenshot from Atari 8-bit computer] |
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Doubly-linked_list_element_removal.png Screenshot from Atari 8-bit computer] |
||
Line 121: | Line 121: | ||
=={{header|Ada}}== |
=={{header|Ada}}== |
||
< |
<syntaxhighlight lang="ada">with Ada.Containers.Indefinite_Doubly_Linked_Lists; |
||
with Ada.Text_Io; |
with Ada.Text_Io; |
||
Line 156: | Line 156: | ||
Print_List (List); |
Print_List (List); |
||
end Element_Remove;</ |
end Element_Remove;</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>cat dog hen horse |
<pre>cat dog hen horse |
||
Line 163: | Line 163: | ||
=={{header|ALGOL W}}== |
=={{header|ALGOL W}}== |
||
Uses the element type and insertion method as in the [[Doubly-Linked List (traversal)]] task. |
Uses the element type and insertion method as in the [[Doubly-Linked List (traversal)]] task. |
||
< |
<syntaxhighlight lang="algolw">begin |
||
% record type to hold an element of a doubly linked list of integers % |
% record type to hold an element of a doubly linked list of integers % |
||
record DListIElement ( reference(DListIElement) prev |
record DListIElement ( reference(DListIElement) prev |
||
Line 240: | Line 240: | ||
end while_e_ne_null |
end while_e_ne_null |
||
end |
end |
||
end.</ |
end.</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 265: | Line 265: | ||
=={{header|Go}}== |
=={{header|Go}}== |
||
Using the doubly-linked list from the container/list package and the Wren example: |
Using the doubly-linked list from the container/list package and the Wren example: |
||
< |
<syntaxhighlight lang="go">package main |
||
import ( |
import ( |
||
Line 290: | Line 290: | ||
dll.Remove(e1) // remove "dog" |
dll.Remove(e1) // remove "dog" |
||
printDll("After removal 2", dll) |
printDll("After removal 2", dll) |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 301: | Line 301: | ||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
Uses code from [[Doubly-Linked List (traversal)]] |
Uses code from [[Doubly-Linked List (traversal)]] |
||
< |
<syntaxhighlight lang="julia">mutable struct DLNode{T} |
||
value::T |
value::T |
||
pred::Union{DLNode{T}, Nothing} |
pred::Union{DLNode{T}, Nothing} |
||
Line 372: | Line 372: | ||
delete(node2) |
delete(node2) |
||
println("Then deleting node2 yields: "); printconnected(node1) |
println("Then deleting node2 yields: "); printconnected(node1) |
||
</ |
</syntaxhighlight>{{out}} |
||
<pre> |
<pre> |
||
From beginning to end: 1 -> 2 -> 3 -> 4 |
From beginning to end: 1 -> 2 -> 3 -> 4 |
||
Line 383: | Line 383: | ||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
This is a simplified version of code from [[Doubly-Linked List (traversal)]] |
This is a simplified version of code from [[Doubly-Linked List (traversal)]] |
||
< |
<syntaxhighlight lang="nim">type |
||
DoublyLinkedList[T] = object |
DoublyLinkedList[T] = object |
||
Line 439: | Line 439: | ||
echo l |
echo l |
||
l.remove c |
l.remove c |
||
echo l</ |
echo l</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 451: | Line 451: | ||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
Extended copy of [[Doubly-linked_list/Traversal#Phix]] |
Extended copy of [[Doubly-linked_list/Traversal#Phix]] |
||
<!--< |
<!--<syntaxhighlight lang="phix">(phixonline)--> |
||
<span style="color: #008080;">enum</span> <span style="color: #000000;">NEXT</span><span style="color: #0000FF;">,</span><span style="color: #000000;">PREV</span><span style="color: #0000FF;">,</span><span style="color: #000000;">DATA</span> |
<span style="color: #008080;">enum</span> <span style="color: #000000;">NEXT</span><span style="color: #0000FF;">,</span><span style="color: #000000;">PREV</span><span style="color: #0000FF;">,</span><span style="color: #000000;">DATA</span> |
||
<span style="color: #008080;">constant</span> <span style="color: #000000;">empty_dll</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{{</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">}}</span> |
<span style="color: #008080;">constant</span> <span style="color: #000000;">empty_dll</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{{</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">}}</span> |
||
Line 502: | Line 502: | ||
<span style="color: #000000;">show</span><span style="color: #0000FF;">(</span><span style="color: #000000;">PREV</span><span style="color: #0000FF;">)</span> |
<span style="color: #000000;">show</span><span style="color: #0000FF;">(</span><span style="color: #000000;">PREV</span><span style="color: #0000FF;">)</span> |
||
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span> |
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 532: | Line 532: | ||
=={{header|Wren}}== |
=={{header|Wren}}== |
||
{{libheader|Wren-llist}} |
{{libheader|Wren-llist}} |
||
< |
<syntaxhighlight lang="ecmascript">import "/llist" for DLinkedList |
||
var dll = DLinkedList.new(["dog", "cat", "bear"]) |
var dll = DLinkedList.new(["dog", "cat", "bear"]) |
||
Line 539: | Line 539: | ||
System.print("After removal 1: %(dll)") |
System.print("After removal 1: %(dll)") |
||
dll.removeAt(0) // remove by index |
dll.removeAt(0) // remove by index |
||
System.print("After removal 2: %(dll)")</ |
System.print("After removal 2: %(dll)")</syntaxhighlight> |
||
{{out}} |
{{out}} |