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

Spread the post

Segregate even and odd nodes in a Linked List

Given an unsorted linked list. modifying this linked list to satisfied following property.

1) Arrange all even node at start.

2) After even node arrange odd nodes.

Given of a example of this problem.

Suppose following data are inserted on linked list.

root_ptr23459811

Try it Yourself

View odd and even nodes

root_ptr23459811

Output

root_ptr35911248

Method


C program to Segregate even and odd nodes in a Linked List .


Output


Code execution: view code execution process.

Stack Areamainroot(pointer)segregate_nodeeven_ptr(pointer)hold(pointer)odd_ptr(pointer)root(pointer)temp(pointer) Heap Areastruct Nodedata (int)= 1next (pointer) struct Nodedata (int)= 1next (pointer) struct Nodedata (int)= 8next (pointer) struct Nodedata (int)= 9next (pointer) struct Nodedata (int)= 5next (pointer) struct Nodedata (int)= 4next (pointer) struct Nodedata (int)= 3next (pointer) struct Nodedata (int)= 2next (pointer)= NULL

Try it yourself

Spread the post

Recommended Posts: