Project 1 - Creation of user defined data type to implement the user interfaces for working with ‘Set’ (Mathematical Set theory) using Linked List
Creation of user defined data type to implement the user interfaces for working with ‘Set’ (Mathematical Set theory) using Linked List
AIM:-
To create a user defined data type to implement the user interfaces for working with set.
OBJECTIVE:-
- Creating two list of data using linked list method.
- Insert the node to 1st and 2nd list accordingly.
- Intersection of data of two lists.
- Getting Union of two list.
PROGRAM:-
#include <stdio.h>
#include <stdlib.h>
struct node
{
int data;
struct node *next;
} *first, *second, *union1, *intersection1;
void initialize()
{
first = second = NULL;
}
void insert(struct node **head, int num)
{
struct node* newNode = (struct node*) malloc(sizeof(struct node));
newNode->data = num;
newNode->next = *head;
*head = newNode;
}
int search(struct node *head, int num)
{
while (head != NULL)
{
if (head->data == num)
{
return 1;
}
head = head->next;
}
return 0;
}
struct node* findunion(struct node *first, struct node *second)
{
union1 = NULL;
struct node *temp = first;
while(temp != NULL)
{
insert(&union1, temp->data);
temp = temp->next;
}
while(second != NULL)
{
if(!search(first,second->data))
{
insert(&union1, second->data);
}
second = second->next;
}
return union1;
}
struct node* intersection(struct node *first, struct node *second)
{
intersection1 = NULL;
while(first != NULL)
{
if(search(second, first->data))
{
insert(&intersection1, first->data);
}
first = first->next;
}
return intersection1;
}
void printLinkedList(struct node *nodePtr)
{
while (nodePtr != NULL)
{
printf("%d", nodePtr->data);
nodePtr = nodePtr->next;
if(nodePtr != NULL)
printf("-->");
}
}
int main()
{
int i, first1, second2, temp;
initialize();
printf("Enter the number for first nodes \n");
scanf("%d", &first1);
printf("Enter %d integers\n", first1);
for(i=0; i<first1; i++)
{
scanf("%d", &temp);
insert(&first, temp);
}
printLinkedList(first);
printf("\nEnter the number for first nodes\n");
scanf("%d", &second2);
printf("Enter %d integers\n", second2);
for(i=0; i<second2; i++)
{
scanf("%d", &temp);
insert(&second, temp);
}
printLinkedList(second);
findunion(first, second);
intersection(first, second);
printf("\nUnion Linked List\n");
printLinkedList(union1);
printf("\nIntersection Linked List\n");
printLinkedList(intersection1);
return 0;
}
COMMAND:-
- struct node.
- newnode.
- while
- if
- printf
- printLinkedlist.
- scanf
RESULT:-
Here first data are stored as data and addressed as next. then initilized a node. Then created a new linklist and point to head then make new node as new head of linked list. Using int search the element Linked List by linearly transversing from head to tail. The union is performed on the two given list .Same as for inserting the second node.

CONCLUTION:-
Has creates a user defined data type to implement the user interfaces for working with set.