c - why this program using single pointer is not working -


if use double pointer instead of single pointer code working properly..

node *pairwiseswap(node *start) {     node *prev=start,*current=start->next;     if(start==null || start->next==null)     return 0;     while(true)     {         node *next=current->next;         current->next=prev;         if(next==null || next->next==null)         {             prev->next=next;             break;         }         prev->next=next->next;**//next next**         prev=next;         current=prev->next;**//appending nodes previous one**     }     return start; } 

    node *prev=start,*current=start->next;     if(start==null || start->next==null) 

here's problem.

if start==null error when doing current=start->next, since trying dereference null pointer

i assume trying on linked list, , want return 0 (a null pointer) in case list has 1 element.

if case, it's enough swap first 2 instructions of function


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -