Created
March 15, 2019 18:02
-
-
Save joxer/4795021d5bbc30b7bc6ec4ffa63a834d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Node { | |
int value; | |
unsigned int pnx; | |
}; | |
unsigned int XOR(struct Node* a, struct Node* b){ | |
return (unsigned int)a ^ (unsigned int)b; | |
} | |
struct Node* insert_first(int value, struct Node* next){ | |
struct Node *node = (struct Node*) malloc(sizeof(struct Node)); | |
node->value = value; | |
node->pnx = XOR(next, NULL); | |
if(next != NULL){ | |
next->pnx = XOR( node, (struct Node*)next->pnx); | |
} | |
return node; | |
} | |
int main(){ | |
struct Node* node = insert_first(3, NULL); | |
node = insert_first(4, node); | |
struct Node* next= (struct Node*) XOR( (struct Node*)node->pnx, NULL); | |
struct Node* prev= (struct Node*) XOR( (struct Node*)next->pnx, NULL); | |
printf("%d %u\n", node->value, node->pnx); | |
printf("%d %u\n", next->value, next->pnx); | |
printf("%d %u\n", prev->value, prev->pnx); | |
// print_list(node); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment