Monday, October 28, 2019

C++: Segregate even and odd nodes in a linked list.

In this C++ tutorial, we will learn how to segregate even and odd nodes in a linked list.

We are given a singly linked list with even and odd nodes at random positions. What we need to do is segregate even and odd nodes such that all the even nodes comes first and then the odd nodes. Below is the code for the algorithm in C++.


Output:

Before segregation- 17 15 8 12 10 5 4 1 7 6
After segregation- 8 12 10 4 6 17 15 5 1 7


No comments:

Post a Comment