Doubly-linked list/Element definition: Difference between revisions

From Rosetta Code
Content added Content deleted
No edit summary
Line 25: Line 25:
[[Category:Pop11]]
[[Category:Pop11]]


uses objectclass;
uses objectclass;
define :class Link;
define :class Link;
slot next = [];
slot next = [];
slot prev = [];
slot prev = [];
slot data = [];
slot data = [];
enddefine;
enddefine;

Revision as of 02:30, 13 May 2007

Task
Doubly-linked list/Element definition
You are encouraged to solve this task according to the task description, using any language you may know.

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.

Ada

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

C

struct link {
  struct * link next;
  struct * link prev;
  int data;
};


Pop11

uses objectclass;
define :class Link;
    slot next = [];
    slot prev = [];
    slot data = [];
enddefine;