Learn basic concept of c , c++ and python programming in regularcodes.com

Spread the post

Print linked list node at alternate position (iterative approach)

Time complexity of this program O(n)

Below in C implementation of this problem. Iterative approach.

Accepted Output

Before swapped alternate data :

Linked list data is : 14, 315, 34, 715, 233, 36, 66, 622, 616

Operation 14<-->315 34<-->715 233<-->36 66<-->622 616

After swapped alternate data :

Linked list data is : 315, 14, 715, 34, 36, 233, 622, 66, 616

Output
 Case  Empty Linked list 
 	 Output Empty linked List
Linked list data is : 14  315  34  715  233  36  66  622  616  

 print alternate data : 
  Linked list data is : 315  14  715  34  36  233  622  66  616  

 Free linked list Node element  

Print linked list node at alternate position (recursive approach)

Time complexity of this program O(n)

Below in C implementation of this problem. Recursive approach.

Accepted Output

Before swapped alternate data :

Linked list data is : 14, 315, 34, 715, 233, 36, 66, 622, 616

Operation 14<-->315 34<-->715 233<-->36 66<-->622 616

After swapped alternate data :

Linked list data is : 315, 14, 715, 34, 36, 233, 622, 66, 616

Output
 Case  Empty Linked list 
 	 Output Empty linked List
Linked list data is : 14  315  34  715  233  36  66  622  616  

 print alternate data : 
  Linked list data is : 315  14  715  34  36  233  622  66  616  

 Free linked list Node element 

Spread the post