Linked List
Linked List
STRUCTURE
LINKED LIST
A Linked list or one way list is linear collection of data
elements, called nodes, where linear order is given by
means of pointers.
Each node is divided into two parts:
INFO Part: first part of node contains the information
part of the node. We can access the info part of node
using INFO[PTR]
LINK Part: Second part of the node contains the address
of next node in the list. We can access the link part of
node using LINK[PTR]
PTR
INFO LINKLINK
Linked List
The NULL pointer denoted by ’X’, signals the end of
the list.
The linked list also contains a list pointer variable,
START or NAME, which contains the address of the
first node of the list.
If START = NULL, then it indicates that Linked List is
empty.
Linked List
Our traversing algorithm uses a pointer variable ‘PTR’
which points to the node currently being processed.
LINK[PTR] points to the next node to be processed.
Thus
PTR = LINK[PTR] moves the pointer to next node in the
list.
Traversing a Linked List
To Count number of elements in
a given Linked List
Searching a Linked List
(Unsorted)
Searching a Linked List
(Sorted)
Memory Allocation
The maintenance of linked list in memory assumes the
possibility of inserting new nodes in Linked List and hence
requires some mechanism which provides unused
memory space for new nodes.
Some mechanism is also needed whereby the memory
space of deleted nodes becomes available for future use.
So, a special linked list is maintained in memory which
consists of unused memory cells.
This list, which has its own pointer is called list of
available space
Avail
X
OVERFLOW and UNDERFLOW
OVERFLOW:
Avail = NULL
UNDERFLOW:
Start = NULL
Insertion into a Linked List
Insertion at the Beginning of a list
Insertion after a Given Node
Insertion into a sorted Linked List
Insertion into a Sorted Linked
List
INSERT(INFO,LINK,START,AVAIL,ITEM)
1) CALL FINDA(INFO, LINK, START, ITEM, LOC)
2) CALL INSLOC(INFO, LINK, START, AVAIL, LOC, ITEM)
Deletion after a given
node
Deletion from a linked list
Deleting a node with given item
of information
Deleting a node with given item
of information
Implementation of STACK using
Linked list
PUSH OPeration
POP OPERATION
Linked representation of QUEUE
Inserting into a QUEUE
Deletion from a Queue
Header Linked List
A header linked list is a linked list which
contains a special node, called header
node at the beginning of the list.
Two types:
Grounded Header List is a linked list
where the last node contains NULL
pointer
A Circular header List is a linked list
where the last node points back to the
header node
Header Linked List
Traversing a Circular
Header List
Searching in a Circular Linked
List
Deleting a node from circular
linked List
Deleting a node from circular
linked List
Delcir(Info,Link, Start, Avail, Item)
1. FINDBHL(Info, Link, Start, Item, LOC, LOCP)
2. If LOC = NULL then print(“Item does not
exist”) and Exit.
3. Link[LOCP] = Link[LOC]
4. Link[LOC] = Avail and Avail = LOC
5. Exit
Applications of Linked lIst
Linked List can be used for
polynomial representation and
performing operations on Linked
List.
Polynomial representation
Polynomial representation using
Header Circular Linked List
Two Way Linked List
Two Way Linked List
Two Way Linked List
Two Way Linked List
Deleting from a Two Way Linked
List
Insertion Between two
nodes