//******** PROJECT-1********
#include <stdio.h>
#include <stdlib.h>
struct node
{
int data;
struct node *next;
} *LLOne, *LLTwo, *unionofLL, *intersectionofLL;
void insert (struct node **head, int num)//creating function for insert node
{
/* Create a new Linked List node */
struct node *newNode = (struct node *) malloc (sizeof (struct node));
newNode->data = num;
newNode->next = *head;
*head = newNode;
}
// comparing an element
int compare(struct node *head, int num)
{
while (head != NULL)
{
if (head->data == num)
{
return 1;
}
head = head->next;
}
return 0;
}
struct node * findunion (struct node *LLOne, struct node *LLTwo) // function for find union
{
unionofLL = NULL;
// Add all nodes of first Linked List to unionLL
struct node *temp = LLOne;
while (temp != NULL)
{
insert (&unionofLL, temp->data);
temp = temp->next;
}
// Insert those nodes of LLTwo which is not present in LLOne
while (LLTwo != NULL)
{
if (!compare (LLOne, LLTwo->data))
{
insert (&unionofLL, LLTwo->data);
}
LLTwo = LLTwo->next;
}
return unionofLL;
}
struct node * intersection (struct node *LLOne, struct node *LLTwo)
{
intersectionofLL = NULL;
while (LLOne != NULL)
{
if (compare(LLTwo, LLOne->data))
{
insert (&intersectionofLL, LLOne->data);
}
LLOne = LLOne->next;
}
return intersectionofLL;
}
void display(struct node *nodePtr)
{
while (nodePtr != NULL)
{
printf ("%d", nodePtr->data);
fflush(stdout);
nodePtr = nodePtr->next;
if (nodePtr != NULL)
printf ("-");
fflush(stdout);
}
}
int main ()
{
int i, LLOneCount, LLTwoCount, temp;
printf ("Enter number of nodes in first Linked List\n");
fflush(stdout);
scanf ("%d", &LLOneCount);
printf ("Enter %d data\n", LLOneCount);
fflush(stdout);
for (i = 0; i < LLOneCount; i++)