Linked List Intersection

Download the file and modify the driver.cpp file by implementing the function called listIntersection(). The function will take the intersection of the list1 and list2 parameters and will place the results in a third parameter called results. The prototype for this function is as follows:


void listIntersection(linkedListType& results,

linkedListType& list1,

linkedListType& list2);

The results of the intersection between two lists (e.g. list1 and list2) will consist of all of the elements in list1 that are also in list2, but no other elements. For example, given list1 = {10, 20, 12, 12, 13, 14} and list2 = {14, 12, 10, 30, 31, 31}, then the intersection between list1 and list2 would be results = {10, 12, 14}. Duplicate elements should not appear in the results list.

Hint: You only need to modify the areas of the code in the driver.cpp file that are marked with the TODO comments. Everything else should remain that same. You can implement this function anyway you like, but you must use the provided lists and function prototype. The printList() function provides an example on how to use a for-loop with an iterator for a passed in list parameter.

Output: The output for the program after the function is implemented should appear as follows:

List 1:

21 41 86 34 71 89 11 34 76 76

List 2:

76 41 8 64 11 89 31 24 86 86

List 1 intersected with List 2:

41 86 89 11 76

** Press any key to continue **

New Download