XORing two pointer in c++

221 views Asked by At

I want to implement an XOR linked list in c++.

I wrote a function that give me the XOR of two pointer. Here it is.

XORLinkedList::Node *XORLinkedList::getXOR(XORLinkedList::Node *a, XORLinkedList::Node *b) {

    size_t A = reinterpret_cast<size_t>(a);
    size_t B = reinterpret_cast<size_t>(b);

    return (XORLinkedList::Node *) (A ^ B);
}

I searched and tried to write this and this was what came to my mind.

I don't know if it works or not or it is even right.

if you know how to do it please tell me

0

There are 0 answers