# Modify the List.cpp

modify the List.cpp file to implement details for the predicate function called subset(). The definition of a subset is: given two lists L1 and L2, then L1 is a subset of L2 if and only if every element in L1 is also an element in L2. In addition every list is considered a subset of itself. The prototype for this function is as follows:

template

void subset(list L1, list L2);

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 subset() function will determine if the first passed in list is a subset of the second passed in list (L1 and L2). The function will return true if it is, and false otherwise.

Hint: You only need to modify the areas of the code in the List.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 signature and the list STL library. The implementation will require some thought, but here are a few hints:

1. Start by calling the sort() function on both lists. For example: L1.sort(). This will ensure that items are examined in the proper order or comparison.

2. If the first list is larger than the second list then return false. You can call the size() or length() function to get the size of the list. For example: L1.size().

3. Create two loops, one within the other. Walk through the first list in the first loop and the second list in the second loop.

4. Set the isSubset variable to false within the first loop before calling the second loop.

5. In the second loop, check if the item in list1 is equal to the item in list2. For example:

*itr1 == *itr2. If the items are equal then set the isSubset variable equal to true.

2

Output: The program after the function is implemented will appear as follows:

List 1: 10 30 20 60

List 2: 10 40 20 50 30

List 3: 10 30 60

L1 subset of L1=1

L1 subset of L2=0

L1 subset of L3=0

L2 subset of L1=0

L2 subset of L2=1

L2 subset of L3=0

L3 subset of L1=1

L3 subset of L2=0

L3 subset of L3=1

template

void subset(list L1, list L2);

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 subset() function will determine if the first passed in list is a subset of the second passed in list (L1 and L2). The function will return true if it is, and false otherwise.

Hint: You only need to modify the areas of the code in the List.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 signature and the list STL library. The implementation will require some thought, but here are a few hints:

1. Start by calling the sort() function on both lists. For example: L1.sort(). This will ensure that items are examined in the proper order or comparison.

2. If the first list is larger than the second list then return false. You can call the size() or length() function to get the size of the list. For example: L1.size().

3. Create two loops, one within the other. Walk through the first list in the first loop and the second list in the second loop.

4. Set the isSubset variable to false within the first loop before calling the second loop.

5. In the second loop, check if the item in list1 is equal to the item in list2. For example:

*itr1 == *itr2. If the items are equal then set the isSubset variable equal to true.

2

Output: The program after the function is implemented will appear as follows:

List 1: 10 30 20 60

List 2: 10 40 20 50 30

List 3: 10 30 60

L1 subset of L1=1

L1 subset of L2=0

L1 subset of L3=0

L2 subset of L1=0

L2 subset of L2=1

L2 subset of L3=0

L3 subset of L1=1

L3 subset of L2=0

L3 subset of L3=1

You'll get a 1.1KB .ZIP file.