Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stddef.h>
- #include <stdint.h>
- struct node {
- int x;
- struct node * next;
- };
- void print(struct node * head)
- {
- struct node * n = head;
- struct node * prev = NULL;
- struct node * t;
- do {
- t = n;
- n = (struct node *)((uintptr_t)n->next ^ (uintptr_t)prev);
- prev = t;
- printf("%d ", t->x);
- } while (n);
- printf("\n");
- }
- int main(void)
- {
- struct node nodes[10];
- struct node * prev = NULL;
- size_t i;
- for (i = 0; i < 10; i++) {
- nodes[i].x = i;
- if (i < 9) {
- nodes[i].next = (struct node *)((uintptr_t)prev ^
- (uintptr_t)(nodes + i + 1));
- } else {
- nodes[i].next = prev;
- }
- prev = nodes + i;
- }
- print(nodes);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment