-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdailycoding006.cpp
More file actions
53 lines (40 loc) · 861 Bytes
/
dailycoding006.cpp
File metadata and controls
53 lines (40 loc) · 861 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <iostream>
using std::cout;
using std::endl;
struct Node {
int val;
Node *npx;
};
Node * XOR(Node *a, Node *b) {
return (Node *) ((uintptr_t)(a) ^ (uintptr_t)(b));
}
void insert(Node **head, int data) {
Node *new_node = new Node;
new_node->val = data;
new_node->npx = XOR(NULL, *head);
if (*head) {
Node *next = XOR((*head)->npx, NULL);
(*head)->npx = XOR(new_node, next);
}
*head = new_node;
}
void printList(Node *head) {
Node *curr = head;
Node *prev = NULL;
Node *next;
while (curr) {
cout << curr->val << " ";
next = XOR(prev, curr->npx);
prev = curr;
curr = next;
}
}
int main() {
Node *head = NULL;
insert(&head, 1);
insert(&head, 2);
insert(&head, 3);
insert(&head, 4);
printList(head);
return 0;
}