Given two linked lists, your task is to complete the function makeUnion(), that returns the union of two linked lists. This union should include all the distinct elements only.
The function takes 2 arguments, reference pointer to the head of the first linked list (head1) and reference pointer to the head of the second linked list (head2).
There are multiple test cases and for each test case this function will be called separately.
The function should return reference pointer to the head of the new list that is formed by the union of the two the lists.
Note: The new list formed should be in non-decreasing order.
The task is to complete the function makeUnion() which makes the union of the given two lists.
9 6 4 2 3 8
1 2 8 6 2
1 2 3 4 6 8 9
Testcase 1: Union of the given two lists have elements 1, 2, 3, 4, 6, 8 and 9 in the list.
If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.