I have most of the coding here and there is actually two files. linkedList.h and
ID: 3531613 • Letter: I
Question
I have most of the coding here and there is actually two files. linkedList.h and driver.cpp.. there is only one function that needs adjusting and I will mark it with asteriks. The program needs to take two linkedlist that already have a group of set integers, compare them and return all like ints between the two list with no repeating number.
DRIVER.CPP
#include <iostream>
#include <stdio.h>
#include "linkedList.h"
using namespace std;
template <class Type>
void printList(linkedListType<Type>& list);
template <class Type>
void listIntersection(linkedListType<Type>& results,
linkedListType<Type>& list1,
linkedListType<Type>& 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(34);
list1.insertLast(76);
list1.insertLast(76);
// Add some data to list 1
list2.insertLast(76);
list2.insertLast(41);
list2.insertLast(8);
list2.insertLast(64);
list2.insertLast(11);
list2.insertLast(89);
list2.insertLast(31);
list2.insertLast(24);
list2.insertLast(86);
list2.insertLast(86);
// Print out the lists
cout << " List 1: ";
printList(list1);
cout << " List 2: ";
printList(list2);
listIntersection(results, list1, list2);
cout << " List 1 intersected with List 2: ";
printList(results);
cout << " ** Press any key to continue ** ";
getchar();
return 0;
}
template <class Type>
void printList(linkedListType<Type>& list)
{
for (linkedListIterator<int> itr = list.begin(); itr != list.end(); ++itr)
{
cout << *itr << " ";
}
return;
}
template <class Type>
void listIntersection(linkedListType<Type>& results,
linkedListType<Type>& list1,
linkedListType<Type>& list2)
****************************************************************************
This is where assignment begins. I am getting undeclared errors. I think it has something to do with how I declared some of the items.
****************************************************************************
{
node *t1= list1.header, *t2 = list2.header;
while(t1 != NULL)
{
result.push(t1->data);
t1 = t1->next;
}
while(t2 != NULL)
{
if(!result.isPresent(t2->data))
result.push(t2->data);
t2 = t2->next;
}
return result;
}
//Utility Function to check the presence any data in the list
bool isPresent(int data)
{
node *t = header;
while ( t != NULL )
{
if(data == t->data )
return true;
t = t->next;
}
return false;
}
}
END OF PROGRAM AND ASSIGNMENT
Explanation / Answer
working on it please wait