[Data Structure] XOR LinkedList
An XOR linked list is a type of double-linked list that uses bitwise XOR operation to store address of the previous and next address in one space (thus, reducing storage space). In the traditional double-linked list, each node has to store a prev and next address field. A B C D .. n->n->n .. .. p<-p<-p .. An XOR linked list combines the same information into 1 address field via bitwise XOR (denoted by ⊕) of the prev and next address. A B C D E .. p⊕n p⊕n p⊕n .. Getting the next address space When traversing from left to right, suppose the cursor is at C, the address of previous item B can be XORed with the value of linked field of C (B⊕D) to get the address for D. ie. addr(D) = link(C) ⊕ addr(B) where link(C) = addr(B) ⊕ addr(D) so addr(D) = addr(B) ⊕ addr(D) ⊕ addr(B) since X⊕X = 0 => addr(D) = 0 ⊕ addr(D) since X⊕0 = X => addr(D) = addr(D) The XOR operation can