Spread the post

Delete Odd key node of given linked list

Suppose given linked list contain following nodes.

Input: 10 15 20 25 30 7 4 11 10

Output: 10 20 30 4 10

Algorithm:

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 odd nodes

View insertion process

Try it yourself

After remove all Odd key nodes linked list is.

root_ptr104302010

Code execution:

Stack Areamainroot(pointer)delete_oddhelper(pointer)root(pointer)temp(pointer) Heap Areastruct Nodedata (int)= 10next (pointer) struct Nodedata (int)= 15next (pointer) struct Nodedata (int)= 20next (pointer) struct Nodedata (int)= 25next (pointer) struct Nodedata (int)= 30next (pointer) struct Nodedata (int)= 7next (pointer) struct Nodedata (int)= 4next (pointer) struct Nodedata (int)= 11next (pointer) struct Nodedata (int)= 10next (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 odd key node of given linked list.

OutPut:

Spread the post

Recommended Posts: