Spread the post

Swap linked list node at alternate position

code execution:

Code execution process Code execution process to swap linked list node Global Variableroot(pointer) Stack Areamainswap_alternate_nodehelp(pointer)temp(pointer) Heap Areastruct Nodedata (int)= 4next (pointer) struct Nodedata (int)= 315next (pointer) struct Nodedata (int)= 34next (pointer) struct Nodedata (int)= 715next (pointer) struct Nodedata (int)= 233next (pointer) struct Nodedata (int)= 36next (pointer) struct Nodedata (int)= 66next (pointer) struct Nodedata (int)= 62next (pointer) struct Nodedata (int)= 616next (pointer)= NULL

Time complexity of this program O(n)

Below in C implementation of this problem.

Accepted Output

Before swapped alternate data :

Linked list data is : 4, 315, 34, 715, 233, 36, 66, 62, 616

After swapped alternate data :

Linked list data is : 315, 4, 715, 34, 36, 233, 62, 66, 616

Output
  Case  Empty Linked list 
   Output Empty linked List

 Before swapped alternate data : 
 Linked list data is : 4  315  34  715  233  36  66  62  616  

 After swapped alternate data : 
 Linked list data is : 315  4  715  34  36  233  62  66  616  

 Free linked list Node element 
 

Spread the post