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


Friday, October 18, 2019

C++: Remove all the duplicates from a sorted linked list.

In this C++ tutorial, we will learn how to remove all the duplicate entries from a sorted linked list. Here is the code for the algorithm in C++ :


Output: 9 8 8 8 7 6 6 5 5 5 5 5 5 5 4 3 3 2 1
             After removing the duplicates -
             9 8 7 6 5 4 3 2 1