Deletion in Circular singly linked list at the endThere are three scenarios of deleting a node in circular singly linked list at the end. 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 element)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 element)If the list contains more than one element, then in order to delete the last element, we need to reach the last node. We also need to keep track of the second last node of the list. For this purpose, the two pointers ptr and preptr are defined. The following sequence of code is used for this purpose. now, we need to make just one more pointer adjustment. We need to make the next pointer of preptr point to the next of ptr (i.e. head) and then make pointer ptr free. Algorithm
Write UNDERFLOW [END OF LOOP] C FunctionOutput 1.Append List 2.Delete Node from end 3.Exit 4.Enter your choice?1 Enter the item 90 Node Inserted 1.Append List 2.Delete Node from end 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