Project 1 - Creation of user defined data type to implement the user interfaces for working with ‘Set’ (Mathematical Set theory) using Linked List
In the first, We created a struct node in that struct we created data of type int and link pointer of type struct node, By using the struct node user defined data type, we created four list there are list1,list2 union list,intersection list, and initialized with NULL.
struct node
{
int data;
struct node *link;
};
struct node *list1=NULL;
struct node *list2=NULL;
struct node *unionll=NULL;
struct node *intersectionll=NULL;
And created 5 funtions there areused for different oparations.
Like inserting data into the list,
void insert(struct node **head, int number) //**h store the address of the root pointer
{
struct node *newnode=(struct node*)malloc(sizeof(struct node));
newnode->data=number;
newnode->link=*head;
*head=newnode;
}
Printing data into the list,
void print(struct node *p)
{
while(p!=NULL)
{
printf("%d ",p->data);
fflush(stdout);
p=p->link;
}
printf("\n");
}
Searching data into the list if same it will return true.
int search(struct node *p,int num)
{
while(p!=NULL)
{
if(p->data==num)
{
return 1;
}
p=p->link;
}
}
And in the unionof funtion return the unionll list that contain union of list1 and list2. and search oparation also done in the unionof function. And in the intersec function it return intersectionll list and in this fuction also search function was called and compare the data in the list1 and list2 and data matches it will insert data into the intersctionll list.