linked list swap function
I'm not sure why the following swap function is not working. When i access the swap function in main i pass it start and start->next
so if i have
A (start)
B (start->next)
i'm certain that's correct but i think it's my swap function that's the problem:
in main :
Code:
charNode* swap(charNode *first, charNode *next)
{
charNode *newList = NULL; /* a reference to the new list that will be used to store the new order */
first = next; /* place next (i.e. B in first and (A) in next) */
next = newList; /* update the list the order that next is in */
newList = first; /* update the list the order that first is in */
return newList; /* return a reference to the new list, which will be used by the print function */
/* a while loop is not necessary in this case because it can be done in one go */
here's how i'm calling it:
Code:
charNode *start = NULL;
start = swap(start, start->next);
printList(start, start);
result:
B
C
D
seems as though 'A's' reference is not updated