How exactly does a XOR Linked list work?

前端 未结 5 2145
悲哀的现实
悲哀的现实 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:36

    XOR has a very special property about it, namely, given a XOR b = c, only two (any two) of the variable are required to compute the the third, with some restrictions. See the XOR swap algorithm for why this works.

    In this case the previous (or next) pointer must still be carried, but only through traversal calculations and not as a seperate member.

提交回复
热议问题