Spread the post

Delete max-length same adjacent nodes of linked list

Write an efficient to delete max-length same adjacent nodes of linked list.

Test cases

1) If linked list are empty show valid user message.

2) If similar group of adjacent node are found. Then finding max length same node pair and delete this node pair.

3) If duplicate adjacent nodes can not found. then not delete linked list nodes.

4) Only delete element of large pair same nodes.

5) If In case two pair are same length then delete first pair.

For example suppose given linked list contain following nodes [3 1 3 1 1 1 5 1 1 ].

root_ptr115111313

View pointers and nodes of this linked list.

Stack Areamainroot(pointer) Heap Areastruct Nodedata (int)= 3next (pointer) struct Nodedata (int)= 1next (pointer) struct Nodedata (int)= 3next (pointer) struct Nodedata (int)= 1next (pointer) struct Nodedata (int)= 1next (pointer) struct Nodedata (int)= 1next (pointer) struct Nodedata (int)= 5next (pointer) struct Nodedata (int)= 1next (pointer) struct Nodedata (int)= 1next (pointer)= NULL

View max length similar adjacent nodes. View in below.

root_ptr115111313

After remove.

root_ptr115313 Stack Areamainroot(pointer) Heap Areastruct Nodedata (int)= 3next (pointer) struct Nodedata (int)= 1next (pointer) struct Nodedata (int)= 3next (pointer) struct Nodedata (int)= 5next (pointer) struct Nodedata (int)= 1next (pointer) struct Nodedata (int)= 1next (pointer)= NULL

View code animation

Program for Delete maximum adjacent similar node group of given linked list.

Spread the post

Recommended Posts: