Swap nodes in a singly-linked list

Why Infinite loop? Infinite loop is because of self loop in your list after calling swap() function. In swap() code following statement is buggy. (*b)->next = (temp1)->next; Why?: Because after the assignment statement in swap() function temp1‘s next starts pointing to b node. And node[b]‘s next point to itself in a loop. And the self … Read more