How to resolve the algorithm Doubly-linked list/Element definition step by step in the PicoLisp programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Doubly-linked list/Element definition step by step in the PicoLisp programming language

Table of Contents

Problem Statement

Define the data structure for a doubly-linked list element. The element should include a data member to hold its value and pointers to both the next element in the list and the previous element in the list. The pointers should be mutable.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Doubly-linked list/Element definition step by step in the PicoLisp programming language

Source code in the picolisp programming language

(de 2tail (X DLst)
   (let L (cdr DLst)
      (con DLst (cons X L NIL))
      (if L
         (con (cdr L) (cdr DLst))
         (set DLst (cdr DLst)) ) ) )

(de 2head (X DLst)
   (let L (car DLst)                  # Get current data list
      (set DLst (cons X NIL L))       # Prepend two new cons pairs
      (if L                           # Unless DLst was empty
         (set (cdr L) (car DLst))     # set new 'prev' link
         (con DLst (car DLst)) ) ) )  # otherwise set 'end' link

# We prepend 'not' to the list in the previous example
(2head 'not *DLst)

  

You may also check:How to resolve the algorithm Find the intersection of two lines step by step in the C# programming language
You may also check:How to resolve the algorithm Palindrome detection step by step in the Processing programming language
You may also check:How to resolve the algorithm Boolean values step by step in the AppleScript programming language
You may also check:How to resolve the algorithm Primality by trial division step by step in the GAP programming language
You may also check:How to resolve the algorithm Active object step by step in the BASIC programming language