Doubly-linked list/Element removal: Difference between revisions

Added solution for Action!
(Added solution for Action!)
Line 6:
 
You may wish to use the list element defined in [[Doubly-Linked List (element)]] for the purposes of this task.
 
=={{header|Action!}}==
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}}
<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!
 
DEFINE NODE_SIZE="6"
TYPE ListNode=[CARD data,prv,nxt]
 
ListNode POINTER listBegin,listEnd
 
PROC Append(CHAR ARRAY v)
ListNode POINTER n
 
n=Alloc(NODE_SIZE)
n.data=v
n.prv=listEnd
n.nxt=0
IF listEnd THEN
listEnd.nxt=n
ELSE
listBegin=n
FI
listEnd=n
RETURN
 
PROC Remove(ListNode POINTER n)
ListNode POINTER prev,next
IF n=0 THEN Break() FI
 
prev=n.prv
next=n.nxt
IF prev THEN
prev.nxt=next
ELSE
listBegin=next
FI
IF next THEN
next.prv=prev
ELSE
listEnd=prev
FI
 
Free(n,NODE_SIZE)
RETURN
 
PROC PrintList()
ListNode POINTER n
 
n=listBegin
Print("(")
WHILE n
DO
Print(n.data)
IF n.nxt THEN
Print(", ")
FI
n=n.nxt
OD
PrintE(")") PutE()
RETURN
 
PROC TestRemove(ListNode POINTER n)
PrintF("Remove ""%S"":%E",n.data)
Remove(n)
PrintList()
RETURN
 
PROC Main()
Put(125) PutE() ;clear screen
AllocInit(0)
listBegin=0
listEnd=0
 
Append("First")
Append("Second")
Append("Third")
Append("Fourth")
Append("Fifth")
PrintList()
 
TestRemove(listBegin.nxt)
TestRemove(listEnd.prv)
TestRemove(listBegin)
TestRemove(listEnd)
TestRemove(listBegin)
RETURN</lang>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Doubly-linked_list_element_removal.png Screenshot from Atari 8-bit computer]
<pre>
(First, Second, Third, Fourth, Fifth)
 
Remove "Second":
(First, Third, Fourth, Fifth)
 
Remove "Fourth":
(First, Third, Fifth)
 
Remove "First":
(Third, Fifth)
 
Remove "Fifth":
(Third)
 
Remove "Third":
()
</pre>
 
=={{header|Ada}}==
Anonymous user