我在查看 XOR 链接列表的实现时多次遇到这段代码,但似乎没有一个人正确解释了这一行(或者也许我错过了一些东西) -
struct node* XOR (struct node *a, struct node *b)
{
return (struct node*) ((unsigned int) (a) ^ (unsigned int) (b));
}
它是如何工作的?谁能解释一下所涉及的 Actor 阵容吗?(请指出之前描述过的任何答案/评论)谢谢!
最佳答案
除了对“a”和“b”指针指向的地址执行通常的异或操作
(unsigned int) (a) ^ (unsigned int) (b)
正是int 到指针的隐式转换(这里是结构节点*)使这段代码能够工作。
(struct node *)(unsigned int someInteger);
编辑:感谢@aruisdante解释第二部分!
关于c - XOR 链表 XOR 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24918632/