Challenge

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

Aim:We are going to create a user defined data type to implement the user interfaces for working with ‘Set’ (Mathematical Set theory).

Over view of the project:

a)We the users 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.

*The mathematical set theory under this project is we have used boolean experssion as an preproceesor directive in the header file,The node pointer,the node declaration head reclaration has made end to end.

*Link list node mainly works on how to insert the node and how the last head reference is pushed toward the output.

#ifndef LIST_H_//header file with an directive as ifndef statement
#define LIST_H_
#include//preprocessor directives
#include//preprocessor directives for calling an a standard library functions
#include//preprocessor directive for an standard boolean expression


typedef struct node //calling an typedef function with struct as an data type
{
	int data;//the data called in the form an int data type
	struct node *next;//pointer next node value is stored in an struct data type
}Node;

Goals:

Implementation of interface for mathematical Set Theory using C programming:

void display_list(Node *head_ref)//calling an pointer head_ref in an display list with Node
{
	if(head_ref==0)//if-else loop getting executed
	{
		printf(" list is empty");//console input statement is printed if above condition is true
	}
	else//execution of an else statement
	{
		tail=head_ref;//head_ref value is added to an tail
		while(tail !=0)//while loop getting exected for an condition tail is not equal to zero
		{
			printf("%d", tail->data);//console input statements for the mentioned conditions i.e tail is greated than data then the value is printed in an integer.
			tail=tail->next;//the value obtained for an tail->next is stored in an tail
		}
		tail=newnode;//the new node value is stored in an tail
	}
Node *get_union(Node *head_pointer1,Node *head_pointer2)//calling an pointer for an head pointer1 and head pointer2 and also an union of an node of the function
{
	while(head_pointer1 !=0)//execution of an while loop for the condition where head pointer1 is not equal to an zero
	{
		head_union= insert_node(head_union,head_pointer1->data);//the obtained value from an insert node condition is store in an head union
		head_pointer1=head_pointer1->next;//the next head pointer1 is stored in an head pointer1
	}
	while(head_pointer2 !=0)//execution of an while loop for the condition where head pointer2 is not equal to an zero
	{
		if(! compare(head_union,head_pointer2->data))//execution of an if statement for comparing an data obtained in an head uinon and head pointer 2
			head_union=insert_node(head_union,head_pointer2->data);//the obtained value from an insert node condition is store in an head union
		head_pointer2=head_pointer2->next;//the next head pointer2 is stored in an head pointer2
	}
	return head_union;//to return from an head union loop statement
}

*Here,we had given two list data as the input first to get union and next to get the intersection using an linklist concept

*The 14 and 17th line it helps in an getting and pushing of an node from the linked list.

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

Keyhighlights and deliverables of the project:

*Here,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.

*newnode=node*

*The above line is used just to create an memeory space.

*head reference value is going to allign with respect to an pointer and also an value to an int declared in the program.

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

*The head and data value has been checked in the comparision by using an headpointer.

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

Main FILE(main. file):

#include"list.h"//header//
int main()//main function//
{
	int first_list_nodes=0,second_list_nodes=0,first_list_items=0,//local variable// //
			second_list_items=0;
	printf("nEnter the number of nodes in first list:");//console input output statements
	fflush(stdout);//To find the bug or to clear the error
	scanf("%d",&first_list_nodes);//console input output statements
	printf("nEnter %d the elements:",first_list_nodes);//console input output statements
	for(int i=0;i < first_list_nodes;i++)//Here for loop got executed
	{
		fflush(stdout);//To find the bug or to clear the error
		scanf("%d",&first_list_items);//console input output statements
		head1=insert_node(head1,first_list_items);//here head1 contains an head1 and first list items
	}
	display_list(head1);//calling display list for an head 1
	printf("nEnter the number of nodes in second list:");//console input output statements
	fflush(stdout);//To find the bug or to clear the error
	scanf("%d",&second_list_nodes);//console input output statements
	printf("nEnter %d the elements:",second_list_nodes);//console input output statements
	for(int i=0;i < second_list_nodes;i++)//calling of for loop to execute the statements
	{
		fflush(stdout);//To find the bug or to clear the error
		scanf("%d",&second_list_items);//console input output statements
		head2=insert_node(head2,second_list_items);//here head2 contains an insert node,head2 and also an second list items
	}
	display_list(head2);//calling display list for the head2
	res_union = get_union(head1,head2);//to find the unit of an head1 and head2 in the get_union resultant is restored in an res_union

#ifdef DEBUG_MAIN//calling an ifdef statements for the debug main
	printf("nValue of Head1 and Head2 :%d %dn",head1,head2);//console input output statements
#endif//end of the if statement
#ifdef DEBUG_MAIN//calling an ifdef statement for union 
	printf("nvalue of Head1 and Head2 after performing union :%d %dn",head1,head2);/console input output statements
	printf("nValue of res_union :%dn",res_union);/console input output statements
#endif//end of the if statement
	printf("Here is the result of union:");//final result of an union
	display_list(res_union);//displaying an list of an res_union
	res_intersection=get_intersection(head1,head2);//get intersection of head1 and head2 is stored in an res intersection
#ifdef DEBUG_MAIN//calling an ifdef statements for res_intersection
	printf("nValue of Head1 and head2 after performing union :%d %dn",head1,head2);
	printf("nValue of res_intersection :%dn",res_intersection);
#endif//end of the if statement
	printf("nHere is the result of intersection:");//final result of an intersection
	display_list(res_intersection);//displaying an list of an res_intersection
}

LIST.SOURCE FILE(.c file):

#include"list.h"//Preprocessor directive of an source file
void display_list(Node *head_ref)//calling an pointer head_ref in an display list with Node
{
	if(head_ref==0)//if-else loop getting executed
	{
		printf(" list is empty");//console input statement is printed if above condition is true
	}
	else//execution of an else statement
	{
		tail=head_ref;//head_ref value is added to an tail
		while(tail !=0)//while loop getting exected for an condition tail is not equal to zero
		{
			printf("%d", tail->data);//console input statements for the mentioned conditions i.e tail is greated than data then the value is printed in an integer.
			tail=tail->next;//the value obtained for an tail->next is stored in an tail
		}
		tail=newnode;//the new node value is stored in an tail
	}
}
Node *insert_node(Node *head_ref,int n)//calling an pointer for an insert node pointing towared an node and also an pointer head ref of an int n pointing toward an node
{
	printf("nInserting Element at the beginning...n");//console input statement to insert the elemnets at the beginning
	newnode=(Node*)malloc(sizeof(Node));//here pointer node is used allong with the malloc and also an size od node just to create an memory space for an new node
	printf("Address of created newnode :%dn",newnode);//to print an address created by an new node
	newnode->data=n;//data n is stored in newnode for the condition which is lesser than the data
	printf("Inserted value is :%dn",newnode->data);//to print the inserted value which is obtained from an newnode data
	newnode->next =head_ref;//head ref value is stored in an new node next
	head_ref=newnode;//new node value is stored in an head ref
	return head_ref;//to return from the pointer of an head reference
}
Node *get_union(Node *head_pointer1,Node *head_pointer2)//calling an pointer for an head pointer1 and head pointer2 and also an union of an node of the function
{
	while(head_pointer1 !=0)//execution of an while loop for the condition where head pointer1 is not equal to an zero
	{
		head_union= insert_node(head_union,head_pointer1->data);//the obtained value from an insert node condition is store in an head union
		head_pointer1=head_pointer1->next;//the next head pointer1 is stored in an head pointer1
	}
	while(head_pointer2 !=0)//execution of an while loop for the condition where head pointer2 is not equal to an zero
	{
		if(! compare(head_union,head_pointer2->data))//execution of an if statement for comparing an data obtained in an head uinon and head pointer 2
			head_union=insert_node(head_union,head_pointer2->data);//the obtained value from an insert node condition is store in an head union
		head_pointer2=head_pointer2->next;//the next head pointer2 is stored in an head pointer2
	}
	return head_union;//to return from an head union loop statement
}
int compare(Node *head,int data)//main function called to comparae the data with an head pointer
{
	while(head != NULL)//execution of an while loop statement for the condition head is not equal to null
	{
		if(head->data == data)//execution of an if loop for the condition where the obtained data is stored in an head
			return 1;//if the above condition satisfy then should return with 1
		head = head->next;//the obtained value of the head next is store in an head
	}
	return 0;//return 0 is executive when it doesnot satisfy the above condition and also to come out of the loop
}
Node *get_intersection(Node *head_pointer1,Node*head_pointer2)//to find the intersection pointer get_intersection is pointing towards both the pointer of an head pointer1 and also to an pointer to an head pointer2
{
	while (head_pointer1 !=0)//execution pf an while loop fro the condition head_pointer which is not equal to an zero
	{
		if(compare(head_pointer2,head_pointer1->data))//execution of an if statement to compare the data between head pointer2 and also an head pointer1
			head_intersection = insert_node(head_intersection,head_pointer1->data);//to holds an data obtained by comparing in an head intersection
		head_pointer1 = head_pointer1->next;//the next data of an head pointer1 is stored in an head pointer1
	}
	return head_intersection;//to return from the head intersection condition
}

LIST.HEADER FILE(.h file):

#ifndef LIST_H_//header file with an directive as ifndef statement
#define LIST_H_
#include//preprocessor directives
#include//preprocessor directives for calling an a standard library functions
#include//preprocessor directive for an standard boolean expression


typedef struct node //calling an typedef function with struct as an data type
{
	int data;//the data called in the form an int data type
	struct node *next;//pointer next node value is stored in an struct data type
}Node;

static Node *head1,*head2,*head_union,*head_intersection,*newnode,*tail,*res_intersection,*res_union;//the ponter *head1,*head2,*head_union,*head_intersection,*newnode,*tail,*res_intersection,*res_unionis pointer in an static node

Node *insert_node(Node *head_ref,int n);//the pointer head reference with an data type o an int of an node is stored ina n pointer insert node
void display_list(Node *head_ref);//pointer head rederence value is get by an void of display list
Node *get_union(Node *head_pointer1,Node *head_pointer2);//the pointer of an both head pointer1 and also an head pointer2 is stored in an get union pointer
Node *get_intersection(Node *head_pointer1,Node *head_pointer2);//the pointer of an both head pointer1 and also an head pointer2 is stored in an get union intersection
int compare(Node *head,int data);//compare the int data with the obtained value of an head pointer

#endif /* LIST_H_ *///to end end the is statement in an header file

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.

*Below you can see first i had given number of nodes for the first list as 5,the elements as 1 2 3 4 5,It is going to allign in an right to left as 5 4 3 2 1 in an link list

*For the second number of nodes entered is of 3

*The elements for these nodes are 5 4 3

*Here we are going to get an result of union as 12345 and the case intersetion similar element are been displayed,Here the result of intersection as 345

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.

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.