Re:XOR Linked List
by codezero on Thursday May 03, 2012 @06:27PM
(#3926112)
Just curious, this wouldn't work for a circularly linked list in the case where there is only one element, right?
[ Parent
| on HN ]
Generally, it doesn't allow you to walk the list given the pointer to an entry. You always need to know the addresses of two adjacent list entries. And yes, this limits its usefulness in practice. I tend to only need doubly linked lists where I want to be able to remove or insert an arbitrary element without walking the list, and you can't do that with an xor list.
Why wouldn't it?
A xor A = 0.
A xor 0 = A.
That should work like a regular circularly linked list or am I missing something?
edit
Doh, now I understand. If this was allowed it wouldn't be possible to have a one-node non-circular list.
It would be the reverse case if it were non-circular, returning 0.