Challenge

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

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

In this project, interfaces for mathematical Set Theory are implemented using C programming language. User can give the input like two list of data and this program will give the output as the union and intersection of these two lists

Goals (2 to 3 points)

  • Implementation of interface for mathematical Set Theory using C programming.
  • Giving two list of data as input to get the output as union & intersection for given list of data

#include <stdio.h>
#include <stdlib.h>

struct node
{
int data;
struct node *next;


} *firstN, *secondN, *unionN, *intersectionNN;

void initialize()

{
firstN = secondN = 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 *firstN, struct node *secondN)

{
unionN = NULL;
struct node *temp = firstN;
while(temp != NULL)
{
insert(&unionN, temp->data);
temp = temp->next;
}
while(secondN != NULL)
{
if(!search(firstN, secondN->data))
{
insert(&unionN, secondN->data);
}
secondN = secondN->next;
}
return unionN;
}
struct node* intersection(struct node *firstN, struct node *secondN)

{
intersectionNN = NULL;
while(firstN != NULL)
{
if(search(secondN, firstN->data))
{
insert(&intersectionNN, firstN->data);
}
firstN = firstN->next;
}
return intersectionNN;
}
int main()

{
int i,firstNCount, secondNCount, temp;
initialize();
printf("Enter number of nodes in first Linked List\n");
scanf("%d", &firstNCount);
printf("Enter %d integers\n", firstNCount);
for(i=0; i<firstNCount; i++)

{
scanf("%d", &temp);
insert(&firstN, temp);
}

printLinkedList(firstN);
printf("\nEnter number of nodes in second Linked List\n");
scanf("%d", &secondNCount);
printf("Enter %d integers\n", secondNCount);
for(i=0; i<secondNCount; i++)

{
scanf("%d", &temp);
insert(&secondN, temp);
}
printLinkedList(secondN);
findunion(firstN, secondN);
intersection(firstN, secondN);
printf("\nUnion Linked List\n");
printLinkedList(unionN);
printf("\nIntersection Linked List\n");
printLinkedList(intersectionNN);

return 0;
}

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.