Doubly-linked list/Element removal: Difference between revisions

Added FreeBASIC
(Added FreeBASIC)
(2 intermediate revisions by 2 users not shown)
Line 10:
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}}
<langsyntaxhighlight Actionlang="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!
Line 98:
TestRemove(listEnd)
TestRemove(listBegin)
RETURN</langsyntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Doubly-linked_list_element_removal.png Screenshot from Atari 8-bit computer]
Line 121:
 
=={{header|Ada}}==
<langsyntaxhighlight Adalang="ada">with Ada.Containers.Indefinite_Doubly_Linked_Lists;
with Ada.Text_Io;
 
Line 156:
Print_List (List);
 
end Element_Remove;</langsyntaxhighlight>
{{out}}
<pre>cat dog hen horse
Line 163:
=={{header|ALGOL W}}==
Uses the element type and insertion method as in the [[Doubly-Linked List (traversal)]] task.
<langsyntaxhighlight lang="algolw">begin
% record type to hold an element of a doubly linked list of integers %
record DListIElement ( reference(DListIElement) prev
Line 240:
end while_e_ne_null
end
end.</langsyntaxhighlight>
{{out}}
<pre>
Line 262:
9000
</pre>
 
=={{header|FreeBASIC}}==
<syntaxhighlight lang="vbnet">Type Nodo
valor As String
sgte As Nodo Ptr
End Type
 
Sub MuestraLista(s As String, Byref cabeza As Nodo Ptr)
Dim As Nodo Ptr e = cabeza
Print s & ": { ";
While e <> 0
Print e->valor; " ";
e = e->sgte
Wend
Print "}"
End Sub
 
Sub Eliminar(Byref cabeza As Nodo Ptr, Byref objetivo As Nodo Ptr)
Dim As Nodo Ptr prev = 0
Dim As Nodo Ptr actual = cabeza
While actual <> objetivo And actual <> 0
prev = actual
actual = actual->sgte
Wend
If actual = objetivo Then
If prev = 0 Then ' cabeza node
cabeza = cabeza->sgte
Else
prev->sgte = actual->sgte
End If
Deallocate(actual)
End If
End Sub
 
Dim As Nodo Ptr dll = 0
Dim As Nodo Ptr e1 = Callocate(1, Sizeof(Nodo))
e1->valor = "dog"
e1->sgte = dll
dll = e1
 
Dim As Nodo Ptr e2 = Callocate(1, Sizeof(Nodo))
e2->valor = "cat"
e2->sgte = dll
dll = e2
 
Dim As Nodo Ptr e3 = Callocate(1, Sizeof(Nodo))
e3->valor = "bear"
e3->sgte = dll
dll = e3
 
MuestraLista("Before removals", dll)
Eliminar(dll, e2) ' remove "cat"
MuestraLista("After removal 1", dll)
Eliminar(dll, e1) ' remove "dog"
MuestraLista("After removal 2", dll)
 
Sleep</syntaxhighlight>
{{out}}
<pre>Before removals: { bear cat dog }
After removal 1: { bear dog }
After removal 2: { bear }</pre>
 
=={{header|Go}}==
Using the doubly-linked list from the container/list package and the Wren example:
<langsyntaxhighlight lang="go">package main
 
import (
Line 290 ⟶ 351:
dll.Remove(e1) // remove "dog"
printDll("After removal 2", dll)
}</langsyntaxhighlight>
 
{{out}}
Line 301 ⟶ 362:
=={{header|Julia}}==
Uses code from [[Doubly-Linked List (traversal)]]
<langsyntaxhighlight lang="julia">mutable struct DLNode{T}
value::T
pred::Union{DLNode{T}, Nothing}
Line 372 ⟶ 433:
delete(node2)
println("Then deleting node2 yields: "); printconnected(node1)
</langsyntaxhighlight>{{out}}
<pre>
From beginning to end: 1 -> 2 -> 3 -> 4
Line 383 ⟶ 444:
=={{header|Nim}}==
This is a simplified version of code from [[Doubly-Linked List (traversal)]]
<langsyntaxhighlight Nimlang="nim">type
 
DoublyLinkedList[T] = object
Line 439 ⟶ 500:
echo l
l.remove c
echo l</langsyntaxhighlight>
 
{{out}}
Line 451 ⟶ 512:
=={{header|Phix}}==
Extended copy of [[Doubly-linked_list/Traversal#Phix]]
<!--<langsyntaxhighlight Phixlang="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;">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 ⟶ 563:
<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>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 532 ⟶ 593:
=={{header|Wren}}==
{{libheader|Wren-llist}}
<langsyntaxhighlight ecmascriptlang="wren">import "./llist" for DLinkedList
 
var dll = DLinkedList.new(["dog", "cat", "bear"])
Line 539 ⟶ 600:
System.print("After removal 1: %(dll)")
dll.removeAt(0) // remove by index
System.print("After removal 2: %(dll)")</langsyntaxhighlight>
 
{{out}}
2,130

edits