How exactly does a XOR Linked list work?

前端 未结 5 2135
悲哀的现实
悲哀的现实 2020-12-16 10:15

The following link explains it.
The implementation is said to work by storing the XOR of the previous and next address(say nxp), instead of storing both(previous and

5条回答
  •  臣服心动
    2020-12-16 10:32

    Double linked list needs 2*N pointers stored for N nodes, plus at least one additional pointer(head, or perhaps head and tail).

    XOR linked list needs N pointers stored for N nodes, plus at least two additional pointers (head and last visited node, or perhaps head and tail and last visited node). While traversing, you store one node (the last visited node), but when you go to the next node, you rewrite that with the now-previous node's address.

提交回复
热议问题