Project 1 - Creation of user defined data type to implement the user interfaces for working with ‘Set’ (Mathematical Set theory) using Linked List
PROGRAM:
=============
#include<stdio.h>
#include<stdlib.h>
int tmpK=0,val,count=0, it1=1,it2=0,inter=0,inter2=0;
struct linkedList
{
int num;
struct linkedList* addr;
};
struct linkedList * unionT;
struct linkedList * union_out;
struct linkedList * intersection;
struct linkedList * intersection_out;
struct linkedList * tmp;
struct linkedList * tmpM;
struct linkedList * head_A;
struct linkedList * head_B;
void COMPARE();
void input(struct linkedList *, int);
void display(struct linkedList*);
int main()
{
int a,b;
printf("\nEnter number of elements required in SET A : ");
fflush(stdout);
scanf("%d",&a);
printf("\nEnter number of elements required in SET B : ");
fflush(stdout);
scanf("%d",&b);
unionT=malloc(sizeof(struct linkedList));
union_out=unionT;
intersection=malloc(sizeof(struct linkedList));
intersection_out=intersection;
head_A=malloc(sizeof(struct linkedList));
head_B=malloc(sizeof(struct linkedList));
printf("\nEnter SET_A values : ");
input(head_A,a);
printf("\nEnter SET_B values : ");
input(head_B,b);
printf("\n\nSET_A values : \n");
display(head_A);
printf("\n\nSET_B values : \n");
display(head_B);
COMPARE();
printf("\n\nUNION values: \n");
display(union_out);
if(inter==0)
{
intersection_out=NULL;
}
printf("\n\nINTERSECTION values: \n");
display(intersection_out);
}
void input(struct linkedList * head,int BB)
{
tmp=head;
for(int i=1;i<BB;i++)
{
fflush(stdout);
scanf("%d",&val);
tmp->num=val;
tmp->addr=malloc(sizeof(struct linkedList ));
tmp=tmp->addr;
}
fflush(stdout);
scanf("%d",&val);
tmp->num=val;
tmp->addr=NULL;
}
void display(struct linkedList * head)
{
tmp=head;
while(tmp!=NULL)
{
printf("%d ",tmp->num);
tmp=tmp->addr;
}
}
void COMPARE()
{
tmp=head_A;
while(tmp!=NULL)
{
tmpM=head_B;
while(tmpM!=NULL)
{
it2++;
if(it1==1)
{
if(it2==1)
{
if(tmp->num!=tmpM->num)
{
unionT->num=tmp->num;
unionT->addr=malloc(sizeof(struct linkedList));
unionT=unionT->addr;
unionT->num=tmpM->num;
unionT->addr=NULL;
}
else
{
unionT->num=tmp->num;
unionT->addr=NULL;
intersection->num=tmp->num;
intersection->addr=NULL;
inter++;
}
}
else
{
if(tmp->num==tmpM->num)
{
if(inter==0)
{
intersection->num=tmpM->num;
intersection->addr=NULL;
inter++;
}
else
{
intersection->addr=malloc(sizeof(struct linkedList));
intersection=intersection->addr;
intersection->num=tmpM->num;
intersection->addr=NULL;
}
}
else
{
unionT->addr=malloc(sizeof(struct linkedList));
unionT=unionT->addr;
unionT->num=tmpM->num;
unionT->addr=NULL;
}
}
}
else
{
if(it2==1)
{
if(tmp->num==tmpM->num)
{
if(inter==0)
{
intersection->num=tmp->num;
intersection->addr=NULL;
inter++;
inter2++;
}
else
{
intersection->addr=malloc(sizeof(struct linkedList));
intersection=intersection->addr;
intersection->num=tmp->num;
intersection->addr=NULL;
inter2++;
}
}
}
else
{
if(tmp->num==tmpM->num)
{
if(inter==0)
{
inter2++;
intersection->num=tmp->num;
intersection->addr=NULL;
inter++;
}
else
{
inter2++;
intersection->addr=malloc(sizeof(struct linkedList));
intersection=intersection->addr;
intersection->num=tmp->num;
intersection->addr=NULL;
}
}
}
}
tmpM=tmpM->addr;
}
if((inter2==0)&&(it1!=1))
{
unionT->addr=malloc(sizeof(struct linkedList));
unionT=unionT->addr;
unionT->num=tmp->num;
unionT->addr=NULL;
}
it2=1;
it1++;
inter2=0;
tmp=tmp->addr;
}
}
=====================================================================
Output:
==============


- Rahul SinghHello I want to know something can you call 9621015501