Guest User

Untitled

a guest
Jul 24th, 2015
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stddef.h>
  3. #include <stdint.h>
  4.  
  5. struct node {
  6. int x;
  7. struct node * next;
  8. };
  9.  
  10. void print(struct node * head)
  11. {
  12. struct node * n = head;
  13. struct node * prev = NULL;
  14. struct node * t;
  15. do {
  16. t = n;
  17. n = (struct node *)((uintptr_t)n->next ^ (uintptr_t)prev);
  18. prev = t;
  19.  
  20. printf("%d ", t->x);
  21. } while (n);
  22. printf("\n");
  23. }
  24.  
  25. int main(void)
  26. {
  27. struct node nodes[10];
  28. struct node * prev = NULL;
  29. size_t i;
  30.  
  31. for (i = 0; i < 10; i++) {
  32. nodes[i].x = i;
  33. if (i < 9) {
  34. nodes[i].next = (struct node *)((uintptr_t)prev ^
  35. (uintptr_t)(nodes + i + 1));
  36. } else {
  37. nodes[i].next = prev;
  38. }
  39. prev = nodes + i;
  40. }
  41.  
  42. print(nodes);
  43.  
  44. return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment