i'm still having trouble figuring it out. I know how the original swap function works. I'm just not sure how to update it so it includes A at the start without skipping a i.e. A, , B, D

correct me if i'm wrong with the original swap function here's what happens:

Code:

charNode *temp = b->next; /* get whatever is AFTER b, in this case C. store it somewhere */
b->next = a; /* swap a and b around to form B, A */
a->next = temp; /* get the stored value from temp (c) and store it AFTER a(A)->next(C). to form BAC */

and i've tried implementing the same approach, visuallised it with a deck of cards named a,b,c,d.

here's what i came up with:

Code:

charNode *temp = a; /* store a */
charNode *temp2 = b; /* store b */
charNode *temp3 = b->next; /* store whatever is after b (c) */
a->next = temp3; (store C to a->next(B)) to form A,CB)
a->next->next->next = temp2; (update the list to form A,C,B,D)
a = temp; (place A at the start of the list)

it still gives me A, C, D.

and i tried removing some nodes to form A,B,C

Code:

charNode *temp = a;
charNode *temp2 = a->next;
charNode *temp3 = b->next;
a->next = b->next; /* form A, C works until here */
temp2 = temp3; (place B at the end to form A,C,B) */

prints A,C

B is skipped