Challenge

Project 1 - Creation of user defined data type to implement the user interfaces for working with ‘Set’ (Mathematical Set theory) using Linked List

#include
#include
struct node
{
int data;
struct node*next;
}*LLOne,*LLTwo,*unionLL,*intersectionLL;
void initialize()
{
LLOne=LLTwo=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*LLOne,struct node *LLTwo)
{
unionLL=NULL;
struct node*temp=LLOne;
while(temp!=NULL)
{
insert(&unionLL,temp->data);
temp=temp->next;
}
while(LLTwo!=NULL)
{
if(!search(LLOne,LLTwo->data))
{
insert(&unionLL,LLTwo->data);
}
LLTwo=LLTwo->next;
}
return unionLL;
}
struct node*intersection(struct node *LLOne,struct node **LLTwo)
{
intersectionLL=NULL;
while(LLOne!=NULL)
{
if(search(LLTwo,LLOne->data))
{
insert(&intersectionLL,LLOne->data);
}
LLOne=LLOne->next;
}
return intersectionLL;
}
void printLinkedList(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;
initialize();
printf("Enter number of nodes in first linked list\n");
fflush(stdout);
scanf("%d",&LLOneCount);
printf("Enter %d integers\n",LLOneCount);
fflush(stdout);
for(i=0;i {
scanf("%d",&temp);
insert(&LLOne,temp);
}
printLinkedList(LLOne);
printf("\nEnter number of nodes in second Linked List\n");
fflush(stdout);
scanf("%d",&LLTwoCount);
printf("Enter %d intergers\n",LLTwoCount);
fflush(stdout);
for(i=0;i {
scanf("%d",&temp);
insert(&LLTwo,temp);
}
printLinkedList(LLTwo);
findunion(LLOne,LLTwo);
intersection(LLOne,LLTwo);
printf("\nUnion Linked List\n");
fflush(stdout);
printLinkedList(unionLL);
printf("\nIntersection Linked List\n");
fflush(stdout);
printLinkedList(intersectionLL);
return 0;
}

OUTPUT:

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.