Looking at the first half of the code:

 

pNode = NULL;

pWalk = list1;   pWalk is at the beginning of list1

while( pWalk )   loop while pWalk is not NULL

{

   pNode = pWalk;       set pNode to pWalk while

   pWalk = pWalk->next; pWalk moves to the next node

}

When we get out of the loop, we have walked through

 list1.  pWalk points to NULL and pNode points to the

 last node of list1                                  

 

 

Looking at the second half of the code:

 

temp = list2->next; temp is at the 2nd node of list2

 

pNode->next = temp->next; 

the last node of list1 (or pNode) is now linked to  

the third node of list2 (where temp->next points to)      

        

temp->next = list1;

the next pointer of the second node of list2 now 

points to the first node of list1                 

 

list1 = NULL;  set list1 pointer to NULL

 

 

After

 

 

list1

 

 

list2