Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement