Q._ How do you calculate the pointer difference in a memory efficient double linked list?
Correct the Random Pointer in Doubly Linked ListGiven a doubly linked list having exactly one of the node pointing to a random node in the list, the task is to correct this random pointer in the doubly linked list, such that it points to the expected node. Show
Approach: This can be achieved by simply iterating the list and checking the individual pointers. C++
Java
Python3
C#
Output:
Incorrect Linked List: 1 (-1) 2 (1) 3 (1) 4 (3)
Corrected Linked List: 1 (-1) 2 (1) 3 (2) 4 (3)
Article Tags :
Linked List
doubly linked list Practice Tags :
Linked List |