Deletion in circular singly linked list at beginningIn order to delete a node in circular singly linked list, we need to make a few pointer adjustments. There are three scenarios of deleting a node from circular singly linked list at beginning. Scenario 1: (The list is Empty)If the list is empty then the condition head == NULL will become true, in this case, we just need to print underflow on the screen and make exit. Scenario 2: (The list contains single node)If the list contains single node then, the condition head → next == head will become true. In this case, we need to delete the entire list and make the head pointer free. This will be done by using the following statements. Scenario 3: (The list contains more than one node)If the list contains more than one node then, in that case, we need to traverse the list by using the pointer ptr to reach the last node of the list. This will be done by using the following statements. At the end of the loop, the pointer ptr point to the last node of the list. Since, the last node of the list points to the head node of the list. Therefore this will be changed as now, the last node of the list will point to the next of the head node. Now, free the head pointer by using the free() method in C language. Make the node pointed by the next of the last node, the new head of the list. In this way, the node will be deleted from the circular singly linked list from the beginning. Algorithm
Write UNDERFLOW [END OF LOOP] C FunctionOutput 1.Append List 2.Delete Node from beginning 3.Exit 4.Enter your choice?1 Enter the item 12 Node Inserted 1.Append List 2.Delete Node from beginning 3.Exit 4.Enter your choice?2 Node Deleted Next TopicDoubly Linked List |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India