XOR-trick and PUZZLE (was comma-operator)
McFarland
clay at oravax.UUCP
Sat Jan 30 05:39:22 AEST 1988
In article <cVyaqyy00jaBF6M0=4 at andrew.cmu.edu> bader+ at andrew.cmu.edu (Miles Bader) writes:
>> How can you use the XOR trick to keep a doubly linked list, using only
>> one field for in each record, to code for finding both the following and
>> the previous record?
>
>To make it a bit clearer, you have to be able to find the NEXT record
>given the current and previous records, and find the PREVIOUS record
>given the current and the next record.
To make it a bit clearer all you have to do is XOR it with itself :-}
Of more interest, since you can store n things in a register and get
any of them back given the other n-1 you can store
NEXT ^ PREVIOUS ^ KEY and keep the KGB from deciphering your linked
lists (Now where did I put that key...).
Clay Brooke-McFarland Odyssey Research Associates
--------------------------------------------------------------|
"Wait! There's something we're all overlooking!" Chorus: "What|
is it, Doctor?" "I don't know. I'm overlooking it myself." |
--------------------------------------------------------------|
More information about the Comp.lang.c
mailing list