I think this is the solution what I was looking for:
#include<stdio.h>
typedef struct node_type{
int data;
struct node_type *link;
}node;
typedef node *list;
list head,tail,temp,prev,start,curr;
void listq();
list xor(list a, list b)
{
return (list) ((unsigned) a ^ (unsigned) b);
}
main(){
int n;
char ch;
scanf("%c",&ch);
scanf("%d\n",&n);
head=tail=start=NULL;
if(ch=='y'){
temp=(list)malloc(sizeof(node));
temp->data=n;
temp->link=NULL;
head=start=temp;
prev=NULL;
}
scanf("%c",&ch);
while(ch=='y')
{
temp=(list)malloc(sizeof(node));
scanf("%d\n",&n);
temp->data=n;
temp->link=xor(head,NULL);
head->link=xor(prev,temp);
prev=head;
head=temp;
scanf("%c",&ch);
}
listq();
}
void listq()
{
list curr = head;
list prev = NULL, next;
while (NULL != curr) {
printf("%d ", curr->data);
next = xor(prev, curr->link);
prev = curr;
curr = next;
}
printf("\n");
}