Tuesday, 20 August 2013

printing next element of current node of a linklist

printing next element of current node of a linklist

i have this code to print a linklist [1,2,3]
void reverse(struct node *ptr){
head = ptr;
while(ptr!=NULL){
printf("%d--->",ptr->data);
ptr=ptr->next;
}
}
output : 1-->2-->3
i am trying to print next element of ptr(current node) like
void reverse(struct node *ptr){
head = ptr;
while(ptr!=NULL){
printf("%d--->",ptr->data);
ptr=ptr->next;
printf("%d--->",ptr->data);
}
}
why is not printing 1-->2-->2-->3 ?

No comments:

Post a Comment