Challenge

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

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. and we 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.In this program we have divided the entire program or we have subdivided

the whole program into an two types which we are compiling from an source file and an header file to make

the entire program into an simple.For an mathematical set theory we are going to use an code.The project is

mainly on the concept of an linked list.With the help of an linked list code the uion and the intersetion of the

data has been performed.

GOALS:

  • we had given two list data as the input first to get union and next to get the intersection using an linklist concept.
  • Inserted node which is nothing but an functional name which we are going to declare.

  • By using these mathematical set theory concepts we have implemented in an program to get an respective output.

KEY HIGHLIGHTS OF THE PROJECT

  • we have created an two list of an data using an two link list method,i.e,creating an new node for and 2nd variable in an data.
  • In the display list the top display list is been displayed with an new node where as bottom display list is an tail.

  • At the end head reference is pushed towards an output of the program.

  • Along with address of created new node the inseted value is been displayed.

CODE:

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

struct node
{
int data;
struct node*next;
};
int i ;
struct node*createlist()
{
int n;
struct node*head=NULL,*p,*ptr;
int x,i;
printf("enter no of elements in list :\n");
fflush(stdout);
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("enter the data value:");
fflush(stdout);
scanf("%d",&x);
p=(struct node*)malloc(sizeof(struct node));
p->data=x;
p->next=NULL;
if(head==NULL)
{
head=ptr=p;
}
else
{
ptr->next=p;
ptr=p;
}
}
return head;
}
void displaylist(struct node*list)
{
struct node*p;
p=list;
while(p!=0)
{
printf("%d\t",p->data);
p=p->next;
}

}
int intersecn(struct node*list1,struct node*list2)
{
printf("\n Intersection list:\t");
fflush(stdout);
struct node*temp3=list1;
struct node*temp4=list2;
while(temp3)
{
while(temp4)
{
if(temp3->data==temp4->data)
{
printf("%d\t",temp3->data);

}
temp4=temp4->next;
}
temp3=temp3->next;
temp4=list2;
}
return 0;
}
int unin(struct node*list1,struct node*list2)
{
printf("\n union list :\t");
fflush(stdout);
struct node*temp3=list1;
struct node*temp4=list2;
int flag=1;
displaylist(temp3);
while(temp4)
{
if(temp3->data!=temp4->data)
{
printf("%d\t",temp4->data);

}
temp4=temp4->next;

}
while(temp4)
{
while(temp3)
{
if(temp3->data==temp4->data)
{
flag=0;
}
temp3=temp3->next;
}
if(flag)
{
printf("%d\t",temp3->data);
}
temp4=temp4->next;
temp3=list1;
}
return 0;
}
int main()
{
struct node*list1,*list2;
list1=list2=NULL;

printf("list1 :\n");
list1=createlist();
printf("list2 :\n");
list2=createlist();
printf("\n list 1 is :");
displaylist(list1);
printf("\n list 2 is :");
displaylist(list2);
intersecn(list1,list2);
unin(list1,list2);

}

EXPECTED OUTCOMES:

The number of nodes in the first list has to be entered first And respectively the elemenets has been entered.

  • Inserting element value along with the address can be seen,the inserted value in the link list list will be exactly like a stack with an right to left side.
  • Mainly we need to find an union and an intersetion of an data.

  • Here we are going to get an result of union as 2 4 6 9 10 12 1 3 5 7 9 and the result of intersection as 2 9.

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.