Memory Efficient Doubly Linked List
Conventional Node Definition:
Nodes in Doubly linked list consist of data,
a pointer to the next node and a pointer to the previous node in the list
a pointer to the next node and a pointer to the previous node in the list
class Dou_link_list{
private int data;
private Dou_link_list next;
private Dou_link_list prev;
...........................
}
New Node Defination
A memory efficient version of Doubly Linked List can be created using only one pointer field to traverse the list back and forth.
public class Mem_Eff_DLL{
private int data;
private Mem_Eff_DLL ptrd;
...........................
}
The ptrd pointer field contains the XOR (Exclusive-Or) of pointer to next node and pointer to prev node. It is called XOR Linked List, because it uses bitwise XOR operation to save space for one memory address.
ptrd = pointer to previous node ⊕ pointer to next node
Memory Efficient Doubly Linked List
In the Example above
- The next pointer of N1 is : NULL ⊕ N2
- The next pointer of N2 is : N1 ⊕ N3
- The next pointer of N3 is : N2 ⊕ NULL

No comments:
Post a Comment