Spread the post

Union of two linked list

Given two linked list L1 and L2. Create new linked list L3 their result are union of L1 and L2.

Suppose L1 linked list contain following nodes.

root_ptr483941

View insertion process.

Try it yourself

Suppose L2 linked list contain following nodes.

root_ptr23459811

View insertion process.

Try it yourself

Result:

root_ptr2583941

Algorithm : Find Union.


C program to find union of two linked list.


Output

Code execution: view code execution process.

Stack Areamainl1(pointer)l2(pointer)l3(pointer)submit_listl1(pointer) NULLl2(pointer)l3(pointer)union_findroot(pointer)value (int) =2 Heap Areastruct Nodedata (int)= 1next (pointer) struct Nodedata (int)= 4next (pointer) struct Nodedata (int)= 9next (pointer) struct Nodedata (int)= 3next (pointer) struct Nodedata (int)= 8next (pointer) struct Nodedata (int)= 4next (pointer)= NULLstruct 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)= NULLstruct Nodedata (int)= 1next (pointer) struct Nodedata (int)= 4next (pointer) struct Nodedata (int)= 9next (pointer) struct Nodedata (int)= 3next (pointer) struct Nodedata (int)= 8next (pointer) struct Nodedata (int)= 5next (pointer) struct Nodedata (int)= 2next (pointer)= NULL

Note that not given all step of execution process here. view more.

Try it yourself

Spread the post

Recommended Posts: