Upload
denise-ellis
View
29
Download
3
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
The Linked List
CS 145 Spring 2005
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;
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
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
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
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