Menu will give options to union, intersect or difference.
Something is wrong with functions, prints incorrectly also does the functions incorrectly.
Still couldnt figure out the difference of 2 sets of data
#include<iostream> #include<string> #include <fstream> using namespace std; struct nodeType { int info, info2; nodeType *link,*back,*link2; }; void createList(nodeType*& first, nodeType*& last,nodeType*& first2, nodeType*& last2); void printList(nodeType*& first); void printList2(nodeType*& first2); void printUnion(nodeType*& first); void concatList(nodeType*& first, nodeType*& first2); bool intersectList(nodeType *first,nodeType *first2, int num, int number); int main() { nodeType *first, *last, *first2, *last2; int num, number; bool quit=0; char choice; int searched; createList(first, last, first2, last2);//creates list if (first == NULL) { cout<<"Empty list"<<endl; // system("pause"); //return 0; } else { } while(!quit) { cout<<"---"<<endl; cout<<"Menu"<<endl; cout<<"P: display both linked list"<<endl; cout<<"U: display the union of sets"<<endl; cout<<"I: display the intersection of sets"<<endl; cout<<"D: display the deference of sets"<<endl; cout<<"C: change the numbers n both sets"<<endl; cout<<"Q: Quits"<<endl; cin>>choice; switch(choice) { case ('p'): case ('P'): printList(first); printList2(first2); break; case ('u'): case ('U'): concatList(first,first2); break; case ('i'): case ('I'): intersectList(first,first2,num,number); break; case ('d'): case ('D'): break; case ('c'): case ('C'): createList(first, last, first2, last2);//creates new list break; case ('q'): case ('Q'): quit=1; cout<<endl; break; default: cout<<"Option not on menu"<<endl; }//closes switch }//closes while system("PAUSE"); return 0; } void createList(nodeType*& first, nodeType*& last,nodeType*& first2, nodeType*& last2) { int number, num2; nodeType *newNode, *newNode2; first = NULL; last = NULL; first2 = NULL; last2 = NULL; cout<<"Enter # set/linked list #1 (-999 to end): "; cin>>number; cout<<endl; while (number != -999) { newNode = new nodeType; // create new node newNode->info = number; newNode->link = NULL; if (first == NULL) { first = newNode; last = newNode; } else { last->link = newNode; last = newNode; } cout<<"Enter # set/linked list #1 (-999 to end): "; cin>>number; cout<<endl; } // end of while-loop cout<<"Enter # set/linked list #2 (-999 to end): "; cin>>num2; cout<<endl; while (num2 != -999) { newNode = new nodeType; // create new node newNode->info = num2; newNode->link = NULL; if (first2 == NULL) { first2 = newNode; last2 = newNode; } else { last2->link = newNode; last2 = newNode; } cout<<"Enter # set/linked list #2 (-999 to end): "; cin>>num2; cout<<endl; } // end of while-loop 2 for data set 2 } // end of build list function void printList(nodeType*& first) { cout<<"SetLinked List 1:{"; nodeType *current; current = first; while (current != NULL) { cout << current->info<<","; current = current->link; }cout<<"} "; } void printList2(nodeType*& first2)//print second list { cout<<"SetLinked List 2:{"; nodeType *current; current = first2; while (current != NULL) { cout << current->info<<","; current = current->link; }cout<<"}"<<endl; } void printUnion(nodeType*& first) { cout<<"Union of Sets 1 and 2:{"; nodeType *current; current = first; while (current != NULL) { cout << current->info<<","; current = current->link; }cout<<"} "; } void concatList(nodeType*& first, nodeType*& first2)//does the union/joins two lists { nodeType *ptr; ptr=first; if (ptr!=NULL) { while(ptr->link!=NULL) ptr=ptr->link; ptr->link=first2; }//end if else { first2=first; } printUnion(first); }//closes function bool intersectList(nodeType *first,nodeType *first2, int num, int number) {/*search for an element within list if they have similar sets of data, which ever data not found in set B thats in A print that value.*/ //printList(first); //printList2(first2); bool flag=false; nodeType *ptr; ptr=first; while(number!=-999) { if (first==NULL && first2==NULL) { flag=true; ptr=ptr->link; return 1; cout<<"Number Found."<<number<<endl; } else { return 0; cout<<"Not Found"<<endl; } }//closes while loop }

This post has been edited by jimblumberg: 10 February 2012 - 10:00 AM
Reason for edit:: Added missing Code Tags, Please learn to use them.