KEMBAR78
Ds06 linked list- insert a node at end | PPSX
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
Done so far...
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 Linked List at the End
Algorithm : Insert_End(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]
start
NULL
11
new_node
NULL
Algorithm : Insert_End(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]
//Reach at the at last Node
ptr = start;
while(ptr->next!=NULL)
ptr=ptr->next;
ptr->next = new_node;
new_node->next = NULL;
8/14/2020 (c) Dr. Jyoti Lakhani 4
Insert a Node in Linked List at the End
8/14/2020 5
11 12 13
start First Node Last Node
NULL
10
new_node
Insert a Node in Linked List at the End
8/14/2020 6
11 12 13
start First Node Last Node
10
new_node
Insert a Node in Linked List at the End
8/14/2020 7
11 12 13
start First Node Last Node
NULL
10
new_node
Insert a Node in Linked List at the End
ptr
ptr = start
while(ptr->next!=NULL)
ptr=ptr->next;
8/14/2020 8
11 12 13
start First Node Last Node
Insert a Node in Linked List at the End
ptr
while(ptr->next!=NULL)
ptr=ptr->next;
NULL
10
new_node
8/14/2020 9
11 12 13
start First Node Last Node
NULL
10
new_node
Insert a Node in Linked List at the End
ptr
while(ptr->next!=NULL)
ptr=ptr->next;
8/14/2020 10
11 12 13
start First Node Last Node
10
new_node
Insert a Node in Linked List at the End
ptr
while(ptr->next!=NULL)
ptr=ptr->next;

Ds06 linked list- insert a node at end

  • 1.
    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
  • 2.
    8/14/2020 2 Done sofar... 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
  • 3.
    8/14/2020 (c) Dr.Jyoti Lakhani 3 Insert a Node in Linked List at the End Algorithm : Insert_End(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] start NULL 11 new_node NULL
  • 4.
    Algorithm : Insert_End(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] //Reach at the at last Node ptr = start; while(ptr->next!=NULL) ptr=ptr->next; ptr->next = new_node; new_node->next = NULL; 8/14/2020 (c) Dr. Jyoti Lakhani 4 Insert a Node in Linked List at the End
  • 5.
    8/14/2020 5 11 1213 start First Node Last Node NULL 10 new_node Insert a Node in Linked List at the End
  • 6.
    8/14/2020 6 11 1213 start First Node Last Node 10 new_node Insert a Node in Linked List at the End
  • 7.
    8/14/2020 7 11 1213 start First Node Last Node NULL 10 new_node Insert a Node in Linked List at the End ptr ptr = start while(ptr->next!=NULL) ptr=ptr->next;
  • 8.
    8/14/2020 8 11 1213 start First Node Last Node Insert a Node in Linked List at the End ptr while(ptr->next!=NULL) ptr=ptr->next; NULL 10 new_node
  • 9.
    8/14/2020 9 11 1213 start First Node Last Node NULL 10 new_node Insert a Node in Linked List at the End ptr while(ptr->next!=NULL) ptr=ptr->next;
  • 10.
    8/14/2020 10 11 1213 start First Node Last Node 10 new_node Insert a Node in Linked List at the End ptr while(ptr->next!=NULL) ptr=ptr->next;