Skip to content

Instantly share code, notes, and snippets.

@joxer
Created March 15, 2019 18:02
Show Gist options
  • Save joxer/4795021d5bbc30b7bc6ec4ffa63a834d to your computer and use it in GitHub Desktop.
Save joxer/4795021d5bbc30b7bc6ec4ffa63a834d to your computer and use it in GitHub Desktop.
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