11/28/2020 (c) Dr. Jyoti Lakhani 1
Linked List
Linear Data Structure
Store more than one value in it (Same as array)
11 12 13
start First Node Last Node
pointer
Node Node Node
NULL
8/14/2020 2
Operations of Linked List
Create a Node
Insert Node at Beginning of Linked List
Insert Node at End of Linked List
Insert at a given Location
Insert after or before a given Node
Deletion from Beginning
Deletion from End
Deletion from a given location
Deletion from before or after a given node
Search an item in Linked List
Traverse Linked List
Display Linked List
Count nodes in a Linked List
8/14/2020 (c) Dr. Jyoti Lakhani 3
Insert a Node in LinkedList
Algorithm : Insert_Begin(new_node)
Input : A node to be inserted in the Linked List
Output: Linked List with new node at the beginning
Steps:
1. [Case 1: List is empty]
If start == NULL then
start= new_node
2.[Case 2: List if Non-Empty]
//Insert Node at beginning
new_node->next = start
start = new_node
start
NULL
11
new_node
NULL
8/14/2020 (c) Dr. Jyoti Lakhani 4
Insert a Node in LinkedList
Algorithm : Insert_Begin(new_node)
Input : A node to be inserted in the Linked List
Output: Linked List with new node at the beginning
Steps:
1. [Case 1: List is empty]
If start == NULL then
start= new_node
2.[Case 2: List if Non-Empty]
//Insert Node at beginning
new_node->next = start
start = new_node
10
new_node
11 12 13
startFirst Node Last Node
NULL
10
new_node
8/14/2020 5
Insert a Node at the Beginning of Linked List
11 12 13
start First Node Last Node
NULL
Algorithm : Insert_Begin(new_node)
Input : A node to be inserted in the Linked List
Output: Linked List with new node at the beginning
Steps:
1. [Case 1: List is empty]
If start == NULL then
start= new_node
2.[Case 2: List if Non-Empty]
//Insert Node at beginning
start = new_node
new_node->next = start
8/14/2020 (c) Dr. Jyoti Lakhani 6
Insert a Node in LinkedList
10
new_node
11 12 13
startFirst Node Last Node
NULL
What IF ?
10
new_node
8/14/2020 7
Insert a Node at the Beginning of Linked List
11 12 13
start First Node Last Node
NULL