Project 1 - Creation of user defined data type to implement the user interfaces for working with ‘Set’ (Mathematical Set theory)
Aim: Creation of user define data type to implement the user interfaces for working with 'set'(mathematical set theroy)
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
Goals:
- 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.
key highlights of the project:
- Creating two list of data using linked list method.
- Insert the node to 1st and 2nd list accordingly.
- Intersection of data of two lists.
- Getting Union of two list.
Deliverables of this project:
- Intersection of data of two list.
- Union of data of two list
Expected Outcomes:
- Student will get the Knowledge of creating the nodes using Linked List.
- Getting the intersection and Union of data of two list.
- Comparing the elements of two list.
Program:

#include "list.h"
//*define DEBUG_MAIN
int main()//main function//
{
int first_list_nodes=0,second_list_nodes=0,first_list_items,second_list_items=0;//int variable//
int i;
printf("Enter the number of Nodes in first List:");//print value//
fflush(stdout);//clear chache memory//
scanf("%d",&first_list_nodes);//user address//
printf("Enter %d the elements:",first_list_nodes);//print value//
for(int i=0;i < first_list_nodes;i++)//first line node for loop//
{
fflush(stdout);//clear chache memory//
scanf("%d",&first_list_items);//user addreess//
head1=insert_node(head1,first_list_items);
}
display_list(head1);//decreal display head1 value//
printf("\nEnter the number of Nodes in second List:");//print value//
fflush(stdout);//clear chach memory//
scanf("%d",&second_list_nodes);//second list node user address//
printf("Enter %d the elements:",second_list_nodes);//decreal print value//
for(int i=0;i < second_list_nodes;i++)//second list node for loop//
{
fflush(stdout);//clear chach memory//
scanf("%d",&second_list_items);//userr address//
head2=insert_node(head2,second_list_items);
}
display_list(head2);
res_union = get_union(head1,head2);
#ifdef DEBUG_MAIN
printf("\nValue of Head1 and Head2 :%d %d",head1,head2);
#endif
#ifdef DEBUG_MAIN
printf("\nValue of Head1 and Head2 after performance union :%d %d",head1,head2);
printf("value of res_union :%d\n"res_union);
#endif
printf("Here is the result of union: ");
display_list(res_union);
res_intersection = get_intersection(head1,head2);//res_intersection value//
#ifdef DEBUG_MAIN
printf("\nValue of Head1 and Head2 after performance union :%d %d",head1,head2);
printf("value of res_intersection :%d\n"res_intersection);
#endif
printf("Here is the result of union: ");//decreal print value of union //
display_list(res_intersection);//decreal display//
}
#include"list.h"
void display_list(Node *head_ref)
{
if(head_ref == 0)
{
printf("List is empty.");
}
else
{
tail=head_ref;
while(tail !=0)
{
printf("%d",tail->data);//print of current node value//
tail=tail->next;//current value
}
tail=newnode;
}
#ifdef DEBUG
printf("value of tail is :%d\n",tail);
#endif
}
Node *insert_node(Node *head_ref,int n)
{
printf("\nInserting Elements at the beginning...\n");
newnode=(Node*)malloc(sizeof(Node));
printf("Address of created newnode :5d\n",newnode);
newnode->data=n;
printf("Inserted value is :%d\n",newnode->data);
newnode->next=head_ref;
head_ref=newnode;
return head_ref;
}
Node *get_union(Node *head_pointer1,Node *head_pointer2)
{
while(head_pointer1 !=0)
{
head_union=insert_node(head_union,head_pointer1->data);
head_pointer1=head_pointer1->next;
}
while(head_pointer2 !=0)
{
if(!compare(head_union,head_pointer2->data))
head_union=insert_node(head_union,head_pointer2->data);
head_pointer2=head_pointer2->next;
}
return head_union;
}
int compare(Node *head,int data)//compare node and int variable//
{
while(head!=NULL)
{
if(head->data==data)
return 1;
head=head->next;
}
return 0;
}
Node *get_intersection(Node *head_pointer1,Node *head_pointer2)
{
while(head_pointer1 !=0)
{
if(compare(head_pointer2,head_pointer1->data))
head_intersection=insert_node(head_intersection,head_pointer1->data);
head_pointer1=head_pointer1->next;
}
return head_intersection;
}

#ifndef LIST_H_
#define LIST_H_
#include<stdio.h>//decreal standard input output value//
#include<stdlib.h>//standard library//
#include<stdbool.h>
typedef struct node//struct//
{
int data;//variable//
struct node *next;
}Node;
static Node *head1,*head2,*head,*head_union,*head_intersection,*newnode,*tail,*res_union,*res_intersection;
Node *insert_node(Node *head_ref,int n);
void display_list(Node *head_ref);
Node *get_union(Node *head_pointer1,Node *head_pointer2);
Node *get_intersection(Node *head_pointer1,Node *head_pointer2);
int compare(Node *head,int data);//compare int variable//
#endif /* LIST_H_ */
Output Screenshort:for a 4 node

for a 5 Node Union Result:
