i want to write a swap function for a singly linked list. the function should take 2node pointers as input parameters and exchange their place in the linked list. this is what i tried out :
please point out where i went wrong. thanks in advance!!!Code:void swap(node *p,node *q) { /*assigning the previous and current nodes*/ node *pprev,*qprev; node *pcurr,*qcurr; node *temp; pprev=p; qprev=q; pcurr=p->link; qcurr=q->link; /*swapping for q in the place of p*/ temp=qcurr; pprev->link=temp; temp->link=pcurr->link; /*swapping for p in the place of q*/ temp=pcurr; qprev->link=temp; temp->link=qcurr->link; }