Question
The intersection of two sets consists of only those elements in the first set that are also in the second set. We will use this
The intersection of two sets consists of only those elements in the first set that are also in the second set. We will use this definition for to implement the intersection for two lists. Modify the List.cpp file and implement details for the intersection() function. The prototype for this function is as follows:
template
The implementation will use the C++ Standard Template Library list implementation. The print() function provides an example on how to use an iterator for a given list. The result of the intersection() function will be the elements in the intersection of the two lists. If there are no common elements between the two given lists, then function will return NULL.
The code for list.cpp is below
#include
using namespace std;
template
template
int main(int argc, char **argv) { // Declare list variables list
// Add data to list 1 L1.push_back(39); L1.push_back(81); L1.push_back(66); L1.push_back(65); L1.push_back(96);
// Add data to list 2 L2.push_back(81); L2.push_back(92); L2.push_back(32); L2.push_back(11); L2.push_back(12); L2.push_back(21); L2.push_back(34); L2.push_back(78); L2.push_back(65); L2.push_back(83);
// Add data to list 3 L3.push_back(78); L3.push_back(96); L3.push_back(92); L3.push_back(66); L3.push_back(34); L3.push_back(98); L3.push_back(62);
// Print out the lists cout << "List 1: " << endl; print(L1);
cout << "List 2: " << endl; print(L2);
cout << "List 3: " << endl; print(L3);
cout << endl;
cout << "The intersection of L2 and L2: " << endl; print(intersection(L2, L2));
cout << "The intersection of L1 and L2: " << endl; print(intersection(L1, L2));
cout << "The intersection of L2 and L3: " << endl; print(intersection(L2, L3));
cout << "The intersection of L3 and L1: " << endl; print(intersection(L3, L1));
cout << " ** Press any key to continue ** "; getchar();
return 0; }
template
// Use an iterator to walk the list. Print the value of // for each node. typename list
// Print the value of the node cout << " " << value; }
cout << endl;
return; }
template
// TODO: Implement the details of the intersection() function // here. return resultList; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started