How to resolve the algorithm Doubly-linked list/Element definition step by step in the Ada 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 Ada 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 Ada programming language

Source code in the ada programming language

type Link;
type Link_Access is access Link;
type Link is record
  Next : Link_Access := null;
  Prev : Link_Access := null;
  Data : Integer;
end record;


generic
   type Element_Type is private;
package Linked_List is
   type List_Type is limited private;
...
private
   type List_Element;
   type List_Element_Ptr is access list_element;
   type List_Element is
      record
	 Prev : List_Element_Ptr;
	 Data : Element_Type;
	 Next : List_Element_Ptr;
      end record;
   type List_Type is
      record
	 Head        : List_Element_Ptr;     -- Pointer to first element.
	 Tail        : List_Element_Ptr;     -- Pointer to last element.
	 Cursor      : List_Element_Ptr;     -- Pointer to cursor element.
	 Count       : Natural := 0;         -- Number of items in list.
	 Traversing  : Boolean := False;     -- True when in a traversal.
      end record;
end Linked_List;


type Link is limited record
   Next : not null access Link := Link'Unchecked_Access;
   Prev : not null access Link := Link'Unchecked_Access;
   Data : Integer;
end record;


  

You may also check:How to resolve the algorithm String comparison step by step in the Common Lisp programming language
You may also check:How to resolve the algorithm Conway's Game of Life step by step in the Prolog programming language
You may also check:How to resolve the algorithm Array concatenation step by step in the Aime programming language
You may also check:How to resolve the algorithm Longest common substring step by step in the APL programming language
You may also check:How to resolve the algorithm Program termination step by step in the SenseTalk programming language