Download the file linkedList.zip and modify the driver.cpp file by implementing
ID: 3537367 • Letter: D
Question
Download the file linkedList.zip and modify the driver.cpp file by implementing the helper function called listComplement() . 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:
template
void listComplement(linkedListType& results,
linkedListType& list1,
linkedListType& list2);
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 44 76 77
List 2:
76 41 8 64 21 89 31 24 71 86
The complement of List 1 with List 2 is:
34 11 44 77
** Press any key to continue **
=======================================================
/**
* Driver.cpp - This file contains the driver code to test the
* linkedListType class implementation
*
* TODO: include your name and course number here.
*/
#include
#include
#include "linkedList.h"
using namespace std;
template <class Type>
void printList(linkedListType& list);
template <class Type>
void listComplement(linkedListType& results,
linkedListType& list1,
linkedListType& list2);
int main(int argc, char **argv)
{
// Declare list variables
linkedListType<int> list1;
linkedListType<int> list2;
linkedListType<int> results;
// Add some data to list 1
list1.insertLast(21);
list1.insertLast(41);
list1.insertLast(86);
list1.insertLast(34);
list1.insertLast(71);
list1.insertLast(89);
list1.insertLast(11);
list1.insertLast(44);
list1.insertLast(76);
list1.insertLast(77);
// Add some data to list 2
list2.insertLast(76);
list2.insertLast(41);
list2.insertLast(8);
list2.insertLast(64);
list2.insertLast(21);
list2.insertLast(89);
list2.insertLast(31);
list2.insertLast(24);
list2.insertLast(71);
list2.insertLast(86);
// Print out the lists
cout << " List 1: ";
printList(list1);
cout << " List 2: ";
printList(list2);
listComplement(results, list1, list2);
cout << " The complement of List 1 with List 2 is: ";
printList(results);
cout << " ** Press any key to continue ** ";
getchar();
return 0;
}
template <class Type>
void printList(linkedListType& list)
{
for (linkedListIterator itr = list.begin(); itr != list.end(); ++itr)
{
cout << *itr << " ";
}
return;
}
template <class Type>
void listComplement(linkedListType& results,
linkedListType& list1,
linkedListType& list2)
{
// TODO: Provide the implementation details for this function here. You may
// find the search() method in the linkedListType class useful.
return;
}
Explanation / Answer
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.