0% found this document useful (0 votes)
19 views

02 ListADTImplementation2 - Dynamic

The document discusses different types of linked lists including singly linked lists, doubly linked lists, and circular lists. It describes the components of linked lists including nodes and reference variables. Methods for inserting and deleting nodes from linked lists are also covered.

Uploaded by

Gromwell Galimba
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

02 ListADTImplementation2 - Dynamic

The document discusses different types of linked lists including singly linked lists, doubly linked lists, and circular lists. It describes the components of linked lists including nodes and reference variables. Methods for inserting and deleting nodes from linked lists are also covered.

Uploaded by

Gromwell Galimba
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

List ADT

Dynamic Implementation by Linked List


Linked list
● Nodes linked to one another, the beginning of
the list referenced by a “ reference variable”

● Main components:
- a “reference variable”
- a node
The Underlying Data Structure
● A linked list is a dynamic list, implemented
using reference variables
● This means that the storage needed is
allocated at run-time, according to the length
of the list at any time.
Anatomy of a Node
A node has two parts:
- The item that it holds
- A pointer to the next node
The pointer to the next node allows the
implementation of a linked list.
When the node is not pointing to anything, the
pointer to the next node has a value of NULL.
Essentially this also means the node is at the
end of the list.
Node Java Implementation
Node C Implementation
Linked-List Java Implementation
Detailed Node Class Implementation
Why Not?
Demo
Deleting a Specified Node from a
Linked List
1. Locate the node to delete.
2. Disconnect this node from the linked list by
changing references.
3. Return the node to the system.
Inserting a Node into a Specified
Position
1. Determine the point of insertion
2. Create a new node and store the new data in it.
3. Connect the new node to the linked list by
changing references.
List Variations
● Doubly – Linked Lists

● Each node has 2 reference variables to:


previous node
next node

● Reference variable to the previous node in the


first node is null; similarly, reference variable
to the next node in the last node.
new class Node
Circular Lists
● Is a single-linked list in which the last node
references to the head of the list.

● It allows searches for sequences of items to continue


from a “current position”, rather than always starting
at the head of the list.
Summary
● Lists may be implemented:
- Statically using arrays which must be
declared and are allocated fixed space before
run-time. Index of items in a list are associated
with index of the array.
- Dynamically using nodes which are allocated
at run-time, and linked using reference
variables.
Linked Lists are useful for:
● Maintaining sorted sequences of values.
● Representing sparse data.
● Building other more complex data structures.
Comparison
End

You might also like