Spread the post

Delete even key node of given linked list

Suppose given linked list contain following nodes [1,2,3,4,5,6,4,1,1].

Input: 1-->2-->3-->4-->5-->6-->4-->1-->1--> NULL.

Output: 1-->3-->5-->1-->1--> NULL.


Use two pointer temp and help. if check temp pointer value is odd then remove that node using help pointer. otherwise temp pointer move next menory block. continue this process till upto end of linked list.

Given example:

Delete even nodes

Try it yourself

After remove all Even key nodes linked list is.


Code execution:

Stack Areamainroot(pointer)delete_evenhelper(pointer)root(pointer)temp(pointer) Heap Areastruct Nodedata (int)= 1next (pointer) struct Nodedata (int)= 2next (pointer) struct Nodedata (int)= 3next (pointer) struct Nodedata (int)= 4next (pointer) struct Nodedata (int)= 5next (pointer) struct Nodedata (int)= 6next (pointer) struct Nodedata (int)= 4next (pointer) struct Nodedata (int)= 1next (pointer) struct Nodedata (int)= 1next (pointer)= NULL

Note that not given all step of execution process here.View How to insert linked list element and so on.

Try it yourself

c program to delete even key node of given linked list.


Spread the post

Recommended Posts: