02 ListADTImplementation2 - Dynamic
02 ListADTImplementation2 - Dynamic
● 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