Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. struct Node {
  2. int value;
  3. unsigned int pnx;
  4. };
  5. unsigned int XOR(struct Node* a, struct Node* b){
  6.  
  7. return (unsigned int)a ^ (unsigned int)b;
  8.  
  9. }
  10. struct Node* insert_first(int value, struct Node* next){
  11.  
  12. struct Node *node = (struct Node*) malloc(sizeof(struct Node));
  13. node->value = value;
  14.  
  15. node->pnx = XOR(next, NULL);
  16. if(next != NULL){
  17. next->pnx = XOR( node, (struct Node*)next->pnx);
  18. }
  19. return node;
  20. }
  21.  
  22.  
  23.  
  24. int main(){
  25.  
  26. struct Node* node = insert_first(3, NULL);
  27. node = insert_first(4, node);
  28.  
  29. struct Node* next= (struct Node*) XOR( (struct Node*)node->pnx, NULL);
  30.  
  31. struct Node* prev= (struct Node*) XOR( (struct Node*)next->pnx, NULL);
  32.  
  33. printf("%d %u\n", node->value, node->pnx);
  34. printf("%d %u\n", next->value, next->pnx);
  35. printf("%d %u\n", prev->value, prev->pnx);
  36. // print_list(node);
  37.  
  38. return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement