#include <stdio.h>
#include <stdlib.h>
#define gc getchar_unlocked
inline int scan(){register int n=0,c=gc();while(c<'0'||c>'9')c=gc();while(c<='9'&&c>='0')n=(n<<1)+(n<<3)+c-'0',c=gc();return n;}
typedef struct node
{
int data;
struct node* np; /* XOR of next and previous node */
}node;
node *head, *tail;
struct node* XOR (struct node *a, struct node *b){
return (struct node*) ((unsigned int) (a) ^ (unsigned int) (b));
}
void insert(int data)
{
node
*new_node
= (node
*) malloc(sizeof(node
)); new_node->data = data;
if (NULL == head) {
new_node->np = NULL;
head = tail = new_node;
}
//else if (at_tail) {
else{
new_node->np = XOR(tail, NULL);
tail->np = XOR(new_node, XOR(tail->np, NULL));
tail = new_node;
}
/*else { //code to enter new node at head
new_node->np = XOR(NULL, head);
head->np = XOR(new_node, XOR(NULL, head->np));
head = new_node;
}*/
}
void printList (struct node *head)
{
struct node *curr = head;
struct node *prev = NULL;
struct node *next;
printf ("Following are the nodes of Linked List: \n"); while (curr != NULL){
next = XOR (prev, curr->np);
prev = curr;
curr = next;
}
}
// Driver program to test above functions
int main ()
{
//struct node *head = (struct node *) malloc (sizeof (struct node) );
head = NULL;
int t,n;
t=scan();
while(t--){
n=scan();
insert(n);
}
printList (head);
return (0);
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2RlZmluZSBnYyBnZXRjaGFyX3VubG9ja2VkCmlubGluZSBpbnQgc2Nhbigpe3JlZ2lzdGVyIGludCBuPTAsYz1nYygpO3doaWxlKGM8JzAnfHxjPic5JyljPWdjKCk7d2hpbGUoYzw9JzknJiZjPj0nMCcpbj0objw8MSkrKG48PDMpK2MtJzAnLGM9Z2MoKTtyZXR1cm4gbjt9IAoKdHlwZWRlZiBzdHJ1Y3Qgbm9kZQp7CiAgICBpbnQgZGF0YTsKICAgIHN0cnVjdCBub2RlKiBucDsgIC8qIFhPUiBvZiBuZXh0IGFuZCBwcmV2aW91cyBub2RlICovCn1ub2RlOwpub2RlICpo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