How to resolve the algorithm Doubly-linked list/Definition step by step in the Delphi programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Doubly-linked list/Definition step by step in the Delphi programming language

Table of Contents

Problem Statement

Define the data structure for a complete Doubly Linked List.

Let's start with the solution:

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

Source code in the delphi programming language

program Doubly_linked;

{$APPTYPE CONSOLE}

uses
  System.SysUtils,
  boost.LinkedList;

var
  List: TLinkedList;
  Head, Tail,Current: TLinkedListNode;
  Value:string;

begin
  List := TLinkedList.Create;

  List.AddFirst('.AddFirst() adds at the head.');
  List.AddLast('.AddLast() adds at the tail.');
  Head := List.Find('.AddFirst() adds at the head.');
  List.AddAfter(Head, '.AddAfter() adds after a specified node.');
  Tail := List.Find('.AddLast() adds at the tail.');
  List.AddBefore(Tail, 'Betcha can''t guess what .AddBefore() does.');

  Writeln('Forward:');
  for value in List do
    Writeln(value);

  Writeln(#10'Backward:');

  Current:= Tail;
  while Assigned(Current) do
  begin
    Writeln(Current.Value);
    Current:= Current.Prev;
  end;

  List.Free;
  Readln;
end.


  

You may also check:How to resolve the algorithm Variadic function step by step in the Objective-C programming language
You may also check:How to resolve the algorithm Deal cards for FreeCell step by step in the Groovy programming language
You may also check:How to resolve the algorithm Barnsley fern step by step in the PureBasic programming language
You may also check:How to resolve the algorithm Long year step by step in the Tcl programming language
You may also check:How to resolve the algorithm Floyd-Warshall algorithm step by step in the Go programming language