Challenge

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

PROJECT1:-

Creation of user defined data type to implement the user interfaces for working with "set" (mathematical set theory )using linked list.

program:-

main function program:-

#include"Link_list.h" //customize header file
int main() // main function
{
/* declaration integer function */
int first_list_nodes=0,second_list_nodes=0,first_list_items=0,second_list_items=0;
int i;
printf("\nEnter the number of nodes in first list:"); //print function
fflush(stdout); //this function use to clear output
scanf("%d",&first_list_nodes); //address function
printf("\nEnter %d the elements:",first_list_nodes); //the function print the first_list_node of node
for(i=0;i<first_list_nodes;i++) // for condition to check the first_list_node
{
fflush(stdout); //this function use to clear output
scanf("%d",&first_list_items); //address function
head1=insert_node(head1,first_list_items); //insert node means second_list_node put the head 1
}
display_list(head1); //display the head2 head means overall first_list_node_value

printf("\nEnter the number of nodes in second list:"); //print the second_list_node
fflush(stdout); //this function use to clear output
scanf("%d",&second_list_nodes); //address function
printf("\nEnter %d the elements:",second_list_nodes); //print function
for(int i=0;i<second_list_nodes;i++) // for condition to check the secod_list_node
{
fflush(stdout); //this function use to clear output
scanf("%d",&second_list_items); //address function
head2=insert_node(head2,second_list_items); //insert node means second_list_node put the head 2
}
display_list(head2); //display the head2 head means overall second_list_node_value
/* get union */
res_union=get_union(head1,head2); //res union put the get_union
printf("the result of union:");//print function
display_list(res_union); // display the res union function
/* get intersection function*/
res_intersection=get_intersection(head1,head2); // res_intersection put get_intersection
printf("the result of intersection:"); //print function
display_list(res_intersection); // display res intersection function

}

CUSTOMIZE HEADER FILE PROGRAM:-

#ifndef LINK_LIST_H_
#define LINK_LIST_H_

#include<stdio.h>// the header file use to standard i/o function
#include<stdlib.h> //library header file
#include<stdbool.h>// THIS header file allow boolean data type


typedef struct node /* a new name change to data*/
{
int data; //declaration if integer
struct node*next; //this function create the next function
}Node;
/*call the all variable name of header files */
static Node*head1,*head2,*head_union,*head_intersection,*newnode,*tail,*res_intersection,*res_union;

Node*insert_node(Node*head_ref,int n); //call the function of insert node
void display_list(Node*head_ref);//call the function of display
Node*get_union(Node*linked_list,Node*linked_list2);//call the function 0f union
Node*get_intersection(Node*linked_list1,Node*linked_list2);//call the function of intersection
int compare(Node*head,int data);//call the function of compare

#endif /* LINK_LIST_H_ */

SOURCE FILE PROGRAM:-


#include"Link_list.h" // this customize header file
void display_list(Node*head_ref) //display_list
{
if(head_ref==0) // this condition to check head_ref equal to 0
{
printf("list is empty"); //print the statement
}
else // else condition
{
tail=head_ref; //tail put the head_ref
while(tail !=0) // while condition to check tail not equal to 0
{
printf("%d",tail->data); // print the statement

tail=tail->next; // tail equal to tail next data
}
tail=newnode; //this function tail put the newNode data
}
}
Node*insert_node(Node*head_ref,int n) // insert_node function
{
printf("\nInserting Element at the beginning...\n"); //print the element
newnode=(Node*)malloc(sizeof(Node)); // create the newNode
printf("Address of the newnode:%d\n",newnode); // print the newNode
newnode->data=n; // this function newNode next data equal n of value
printf("Inserted value is :%d\n",newnode->data);
newnode->next=head_ref; //this function create the next newNode
head_ref=newnode; //the newNode put in the head_ref
return head_ref;
}
Node*get_union(Node *linked_list1,Node*linked_list2) // get_union function
{
while(linked_list1 !=0) // the while loop function to check not equal to 0
{
head_union=insert_node(head_union,linked_list1->data); // this function linked_list1 next data insert the head_union
linked_list1=linked_list1->next; //this function take of the next data of linked_list1
}
while(linked_list2 !=0) //the while loop function to check not equal to 0
{
if(!compare(head_union,linked_list2->data)) //the function not compare the head union function
head_union=insert_node(head_union,linked_list2->data);
linked_list2=linked_list2->next; //this function take of the next data of linked_list2
}
return head_union;
}
int compare(Node*head,int data) // compare function
{
while(head !=0) //while loop function check to not equal to 0
{
if(head->data==data)// if condition check to head next data equal to data
return 1;
head=head->next; // this function take of the next data of head
}
return 0;
}
/* a set consists of elements common will present in pointer in present1 and pointer2 */
Node*get_intersection(Node*linked_list1,Node*linked_list2) //intersection function
{
while(linked_list1 !=0) /* the while loop function to check link_list is not equal to 0 */
{
if(compare(linked_list2,linked_list1->data)) /* if condition to compare linked_list1& linkedl_list2*/
head_intersection=insert_node(head_intersection,linked_list1->data); // this function insert the head_inter
linked_list1=linked_list1->next; //this function take of the next data of linked_list1
}
return head_intersection;
}

PROGRAM CODE:-

Main function:-

header file :-

SOURCE file:-

RESULT:-

first_list_node output:-

second_list_node output:-

union output:-

Intersection output:-

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.