The document outlines algorithms for basic operations on linked lists, including traversal, counting nodes, searching, and inserting or deleting nodes in various scenarios. It covers single linked lists, circular linked lists, doubly linked lists, and circular doubly linked lists, detailing specific cases for insertion and deletion. Each algorithm is presented in a step-by-step format for clarity.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
2 views42 pages
Unit 2
The document outlines algorithms for basic operations on linked lists, including traversal, counting nodes, searching, and inserting or deleting nodes in various scenarios. It covers single linked lists, circular linked lists, doubly linked lists, and circular doubly linked lists, detailing specific cases for insertion and deletion. Each algorithm is presented in a step-by-step format for clarity.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 42
Linked list
Basic Operations Linked Lists Algorithm for traversing a linked list
Step 1: [Initialize] Set Ptr = Start
Step 2: Repeat Steps 3 And 4 While Ptr != Null Step 3: Apply Process To Ptr -> Data Step 4: Set Ptr = Ptr -> Next [End Of Loop] Step 5: Exit Algorithm to print the number of nodes in a linked list
Step 1: [Initialize] Set Count =0
Step 2: [Initialize] Set Ptr = Start Step 3: Repeat Teps 4 And 5 While Ptr != Null Step 4: Set Count = +1 Step 5: Set Ptr = Ptr -> Next [End Of Loop] Step 6: Write Count Step 7: Exit Algorithm to search a linked list Step 1: [Initialize] Set Ptr = Start Step 2: Repeat Step 3 While Ptr != Null Step 3: If Val = Ptr ->Data Set Pos = Ptr Go To Step 5 Else Set Ptr = Ptr -> Next [End Of If] [End Of Loop] Step 4: Set Pos = Null Step 5: Exit Inserting a New Node in a Linked List Case 1: The new node is inserted at the beginning. Case 2: The new node is inserted at the end. Case 3: The new node is inserted after a given node. Case 4: The new node is inserted before a given node.
Step 1: If Avail = Null
Write Overflow Go To Step 7 [End Of If] Step 2: Set New_node = Avail Step 3: Set Avail = Avail -> Next Step 4: Set New_node ->Data = Val Step 5: Set New_node -> Next = Start Step 6: Set Start = New_node Step 7: Exit Algorithm new node is inserted at the end Algorithm new node is inserted after a given node. Algorithm new node is inserted before a given node. Algorithm to delete the first node Algorithm to delete the last node Algorithm to delete the node after a given node CIRCULAR LINKED LISTS Inserting a New Node in a Circular Linked List Case 1: The new node is inserted at the beginning of the circular linked list. Case 2: The new node is inserted at the end of the circular linked list. Algorithm new node is inserted at the end of the circular linked list Algorithm to delete the first node Algorithm to delete the last node DOUBLY LINKED LISTS Algorithm to insert a new node at the beginning Algorithm to insert a new node at the end Algorithm to insert a new node after the given node Algorithm to insert a new node before the given node Deleting a Node from a Doubly Linked List
• Case 1: The first node is deleted.
• Case 2: The last node is deleted. • Case 3: The node after a given node is deleted. • Case 4: The node before a given node is deleted. Algorithm to delete the first node Algorithm to delete the last node Algorithm to delete a node after a given node Algorithm to delete a node before a given node CIRCULAR DOUBLY LINKED LISTS Algorithm to insert a new node at the beginning Algorithm to insert a new node at the end Algorithm to delete the first node Algorithm to delete the last node