Spread the post

Remove duplicates from sorted linked list

Suppose given linked list contain following nodes.

Input :1 3 3 3 6 6 7 9

Note: Sort linked list

Output:1 3 6 7 9


using two pointer temp and help_ptr. temp pointer are point to first node of linked list. check if temp pointer next node value are equal to current temp pointer value then help of help_ptr pointer remove that node. view below function.

Given example:

Remove Duplictes

View insertion process.

Try it yourself

After remove Linked list is.


Code execution:

Stack Areamainroot(pointer)remove_duplicatehelp_ptr(pointer)temp(pointer) Heap Areastruct Nodedata (int)= 1next (pointer) struct Nodedata (int)= 3next (pointer) struct Nodedata (int)= 3next (pointer) struct Nodedata (int)= 6next (pointer) struct Nodedata (int)= 6next (pointer) struct Nodedata (int)= 7next (pointer) struct Nodedata (int)= 9next (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 remove duplicate element of sorted linked listt.


Spread the post

Recommended Posts: