In div c please with comments and check output thanks Qcomp
In div c++ // please with comments and check output thanks
Q.complete miss 4 functions in code
-------------------------------------------------------------
Solution
#define NULL 0
 #include <iostream>
/*
 Name: Rabia Saad Al-wethnani
 ID: 43503535
 Section: 2486
 */
using namespace std;
struct Node
 {
 int item; //data
 Node *next; //pointer to the next node in the list
 };
Node* createNode(int);
 int isPresent(Node*, int);
 void appendNode(Node*&, int);
 void displayList(Node*);
 void printLists(Node*, Node*);
 void swapNodes(Node* &head, int s);
 void findIntersection(Node* first, Node* P);
 void findUnion(Node* first, Node* P);
 int main()
 {
 Node* L = NULL, *P = NULL;
appendNode(L, 1);
 appendNode(L, 2);
 appendNode(L, 3);
 appendNode(L, 4);
 appendNode(L, 6);
 appendNode(L, 8);
 displayList(L);
appendNode(P, 1);
 appendNode(P, 2);
 appendNode(P, 4);
 appendNode(P, 6);
 displayList(P);
printLists(L, P); //complete this function
 swapNodes(L, 30); //It should swap the links of nodes 30 and 40 in L.
 findIntersection(L, P); //This method should print 1, 2, 4 ,6
 findUnion(L, P); //It should print 1,2,3,4,6,8
 return 0;
 }
int isPresent(Node* P, int d)
 {
 Node* currNode = P;
 while(currNode != NULL){
 if(currNode->item == d)
 return 1;
 currNode = currNode->next;
 }
 return 0;
 }
void printLists(Node* L, Node* P)
 {
 Node* newList = NULL;
 Node* currNode = L;
 while(currNode != NULL){
 if(isPresent(P, currNode->item))
 appendNode(newList, currNode->item);
 currNode = currNode->next;
 }
displayList(newList);
 //The output of the function should be:
 // 1, 2, 4, 8
 }
//swap the node containing item s with the next node in the list
 void swapNodes(Node* &head, int s)
 {
 //write your code here
 }
 void findIntersection(Node* first, Node* P)
 {
 Node* newList = NULL; //this list should contain intersection of L and P
Node* currNode = first;
 while(currNode != NULL){
 if(isPresent(P, currNode->item))
 appendNode(newList, currNode->item);
 // cout << currNode->item;
 currNode = currNode->next;
 }
 //display the new list after union
 displayList(newList);
 }
 void findUnion(Node* first, Node* P)
 {
 Node* newList = NULL; //this list should contain Union of L and P
Node* currNode = first;
 while(currNode != NULL){
 appendNode(newList, currNode->item);
 currNode = currNode->next;
 }
currNode = P;
 while(currNode != NULL){
 if (!isPresent(newList, currNode->item))
 appendNode(newList, currNode->item);
 currNode = currNode->next;
 }
 //display the new list after union
 displayList(newList);
 }
 Node* createNode(int value)
 {
 Node *node = new Node;
 node->item = value;
 node->next = NULL;
 return node;
 }
void appendNode(Node* &head, int value)
 {
 Node *newNode, *currNode;
 newNode = createNode(value);
 if(head == NULL) //the list is empty
 head = newNode; //make a new list
 else
 { //list is not empty
 currNode = head; //current node points to the list head
while (currNode->next != NULL) //move current node in the list
 currNode = currNode->next;
currNode->next = newNode; //add new node at the end
 }
 }
void displayList(Node* head)
 {
 cout<< \"List:\";
 Node* currNode = head;
while (currNode != NULL)
 {
 cout<<currNode->item<<\", \";
 currNode = currNode->next;
}
 cout<<endl;
 }
PrintList and SwapNode functions are not clear, please explain me once again, what actually you need, will finish



