6
The Linked List CS 145 Spring 2005

The Linked List

Embed Size (px)

DESCRIPTION

The Linked List. CS 145 Spring 2005. List. Node. Node. Node. First. Next. Next. Null. Data. Data. Data. Basic Linked List (AKA Singly Linked List). type Node; type Node_Ptr is access Node; type Node is record Next : Node_Ptr; Data : ; end record;. - PowerPoint PPT Presentation

Citation preview

Page 1: The Linked List

The Linked List

CS 145 Spring 2005

Page 2: The Linked List

Basic Linked List(AKA Singly Linked List)

Next

Data

NodeNext

Data

NodeNull

Data

NodeFirst

List

type Node;type Node_Ptr is access Node;type Node is record Next : Node_Ptr; Data : <<whatever>>;end record;

subtype List is Node_Ptr;

or,

type List is record First : Node_Ptr;end record;

Page 3: The Linked List

Basic Linked List (Variation 1)Point to Data

Next

DataPtr

NodeNext

DataPtr

NodeNull

DataPtr

NodeFirst

List

type Node;type Node_Ptr is access Node;type Node is record Next : Node_Ptr; Data : access <<whatever>>;end record;

subtype List is Node_Ptr;

or,

type List is record First : Node_Ptr;end record;

…Data

…Data

…Data

Page 4: The Linked List

Linked List (Variation 2)Last Pointer

Next

Data

NodeNext

Data

NodeNull

Data

NodeFirst

List

type Node;type Node_Ptr is access Node;type Node is record Next : Node_Ptr; Data : <<whatever>>;end record;

type List is record First : Node_Ptr; Last : Node_Ptr;end record;

Last

Page 5: The Linked List

Linked List (Variation 3)Keep a Count

Next

Data

NodeNext

Data

NodeNull

Data

NodeFirst

List

type Node;type Node_Ptr is access Node;type Node is record Next : Node_Ptr; Data : <<whatever>>;end record;

type List is record First : Node_Ptr; Last : Node_Ptr; Count : Natural;end record;

Last

Count

Page 6: The Linked List

Doubly Linked List(with Optional Count)

First

List

type Node;type Node_Ptr is access Node;type Node is record Next : Node_Ptr; Prev : Node_Ptr; Data : <<whatever>>;end record;

type List is record First : Node_Ptr; Last : Node_Ptr; Count : Natural;end record;

Last

Count

Null

Prev

Node

Data

Next

Prev

Node

Data

Next

Null

Node

Data