How to resolve the algorithm Doubly-linked list/Traversal step by step in the XPL0 programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Doubly-linked list/Traversal step by step in the XPL0 programming language

Table of Contents

Problem Statement

Traverse from the beginning of a doubly-linked list to the end, and from the end to the beginning.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Doubly-linked list/Traversal step by step in the XPL0 programming language

Source code in the xpl0 programming language

def \Node\ Prev, Data, Next;    \Element (Node) definition
def SizeofInt = 4;

    proc Insert(NewNode, Node);     \Insert NewNode after Node
    int  NewNode, Node, NextNode;
    [NextNode:= Node(Next);
    NextNode(Prev):= NewNode;
    NewNode(Next):= NextNode;
    NewNode(Prev):= Node;
    Node(Next):= NewNode;
    ];

int Head(3), Tail(3);           \Doubly linked list definition
int N, NewNode, Node;
[\Further define (initialize) the doubly linked list
Head(Next):= Tail;
Tail(Prev):= Head;
\Insert some Nodes containing square data
for N:= 1 to 10 do
    [NewNode:= Reserve(3*SizeofInt);
    NewNode(Data):= N*N;
    Insert(NewNode, Head);
    ];
\Traverse list from Head to Tail
Node:= Head(Next);
while Node # Tail do
    [IntOut(0, Node(Data));  ChOut(0, ^ );
    Node:= Node(Next);
    ];
CrLf(0);
\Traverse list from Tail to Head
Node:= Tail(Prev);
while Node # Head do
    [IntOut(0, Node(Data));  ChOut(0, ^ );
    Node:= Node(Prev);
    ];
CrLf(0);
]

  

You may also check:How to resolve the algorithm Brilliant numbers step by step in the Java programming language
You may also check:How to resolve the algorithm Convert decimal number to rational step by step in the Java programming language
You may also check:How to resolve the algorithm Hostname step by step in the Groovy programming language
You may also check:How to resolve the algorithm Fibonacci sequence step by step in the Dyalect programming language
You may also check:How to resolve the algorithm MD4 step by step in the Sidef programming language