Challenge

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

OVERVIEW OF THE PROJECT:

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.

GOAL OF THE PROJECT:

  • 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.

KEYHIGHLIGHT OF THE PROJECT:

  • Creating two list of data using linked list method.
  • Insert the node to 1st and 2nd list .
  • Intersection of data of two lists
  • Getting Union of two list.

DELIVERABLES OF THE PROJECT:

  • Getting the union value of two node.
  • Getting the intersection value of two node.

EXPECTED OUTCOME:

Enter total number of value in first node :5

Enter total number of Value in second node :5

Enter the elements of the 1st node :1

Enter the elements of the 1st node :2

Enter the elements of the 1st node :3

Enter the elements of the 1st node :4

Enter the elements of the 1st node :5

Linked list values are : 5
Linked list values are : 4
Linked list values are : 3
Linked list values are : 2
Linked list values are : 1
Enter the elements of the 2nd node : 4

Enter the elements of the 2nd node : 5

Enter the elements of the 2nd node : 3

Enter the elements of the 2nd node : 2

Enter the elements of the 2nd node : 6

Linked list values are : 6
Linked list values are : 2
Linked list values are : 3
Linked list values are : 5
Linked list values are : 4
Union of linked list is :
Linked list values are : 6
Linked list values are : 1
Linked list values are : 2
Linked list values are : 3
Linked list values are : 4
Linked list values are : 5
intersection of linked list is :
Linked list values are : 2
Linked list values are : 3
Linked list values are : 4
Linked list values are : 5

PROGRAM:

#include
#include
//link list node
typedef struct Node
{
int Value;
struct Node *next;
}Node;

static Node *h1; //storing the address of first linked list
static Node *h2; //storing the address of second linked list
static Node *Head;
static Node *Tail;
static Node *Union;// used for union operation
static Node *intersection;//used for intersection operation
static Node *Result_union;//getting the union result
static Node *Result_intersection;//getting the intersection result
static Node *Headnode;
static Node *Newnode;
//Function declaration
Node *Insert( Node *Headnode , int n);
void Display_node(Head);
Node *get_union( Node *h1,Node *h2);
Node *get_intersection( Node *h1, Node *h2);
int compare( Node *Headnode,int n);

//main function
int main()
{
int a; //This variable defines total number of value in first node
int b; //This variable defines total number of value in second node
int c;//This variable defines the element in first node
int d;//This variable defines the element in second node
int i;
printf("nEnter total number of value in first node :");
fflush(stdout);
scanf("%d", &a);

printf("nEnter total number of Value in second node :");
fflush(stdout);
scanf("%d", &b);

//for loop for 1st node
for(i=0;i<a;++i)
{
printf("nEnter the elements of the 1st node :");
fflush(stdout);
scanf("%d", &c);
h1=Insert(h1,c);
}
Display_node(h1);
for(int i=0;i<b;++i)// //for loop for 2nde node
{
printf("nEnter the elements of the 2nd node : ");
fflush(stdout);
scanf("%d",&d);
h2=Insert(h2,d);
}
Display_node(h2);
//calling union function
Result_union=get_union(h1,h2);
printf("n Union of linked list is :");
Display_node(Result_union);
//calling the intersection function
Result_intersection=get_intersection(h1,h2);
printf("n intersection of linked list is :");
Display_node(Result_intersection);
}

//function to insert a node at the beginning of a linked list
Node *Insert( Node *Headnode , int n)
{
Newnode=(Node*)malloc(sizeof(Node));//allocating node
Newnode->Value = n;//putting the data
Newnode->next = Headnode;//link the old list of new node
Headnode = Newnode;//move the head to point to the new node
return Headnode;
}
//Function to print all linked list
void Display_node(Head)
{

if (Head==NULL)
{
printf("nList is empty");
}
else
{
Tail=Head;
while(Tail != NULL)
{
printf("n Linked list values are : %d",Tail -> Value);
Tail = Tail->next;
}
}
}
//Function to get union of two linked lists head1(h1) and head2(h2)
Node *get_union( Node *h1, Node *h2)
{
while(h1 != NULL)
{
Union=Insert(Union,h1->Value);
h1= h1 ->next;
}
while(h2 != NULL)
{
if(!(compare(Union,h2->Value)))
{
Union=Insert(Union,h2 -> Value);
}
h2 = h2->next;
}
return Union;
}
//Function to get intersection of two linked lists head1(h1) and head2(h2)
Node *get_intersection( Node *h1, Node *h2)
{
while(h1 != NULL)
{
if(compare(h2,h1->Value))
{
intersection=Insert(intersection,h1 -> Value);
}
h1 = h1->next;
}
return intersection;
}
//function to compare
int compare( Node *Headnode,int n)
{
while (Headnode != NULL)
{
if((Headnode->Value) == n)
{
return 1;
}
Headnode=Headnode->next;
}
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.