Challenge

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

Overview of the Project: (5 to 6 lines)

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

1.here we taken by the two set of the data A={1 2 3 4 },B={2 3 4 5}.

2.after that we can apply the union and intersection of these data A,B.

Goals (2 to 3 points)

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

3.Union means it will store the all data in the same location.

Node *get_union(Node *head_pointer1,Node *head_pointer2)

4.Intersection means A set that consists of elements common will present in A and B.

Node *get_intersection(Node *head_pointer1,Node*head_pointer2)

Key Highlights of the Project: (4 to 5 point)

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

1.we have taking two different data nodes A and B.

2.after we are perfroming the union,intersection and compare.

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);

Deliverables of this project: (4 to 5 points)

  • Intersection of data of two list.
  • Union of data of two list

Intersection means nothing it will perfroming the two sets of the data by user give in the console of the inputs and after it will be perfroming to check the data by value by value .

ex: A={1 2 3 4 }

after intersection final is: A={ 4 3 2 1}

union means it will store the data in same memory location,a sets of data will be presented in the partucular location.

Expected Outcomes: (4 to 5 points)

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

A after creating the 2 nodes in the linked list .we are perfroming the intersection and union of those A and B.After that we have to do Compare of both nodes

here A={1 2 3 4 },B={2 3 4 5}

after intersection A={4 3 2 1},B ={5 4 3 2}

after compare ={2 3 4}

Main.c

#include"list.h" //header//
int main() //main function//
{

int first_list_nodes=0,second_list_nodes=0,first_list_items=0, //local variable// //here given nodes,items//
second_list_items=0;
printf("\nEnter the number of nodes in first list:"); //printing the node1 list of the console//
fflush(stdout);
scanf("%d",&first_list_nodes); //reads the address//
printf("\nEnter %d the elements:",first_list_nodes); //printing the list1 in the console//
for(int i=0;i < first_list_nodes;i++) //for loop will starts first_list_nodes here//
{
fflush(stdout);
scanf("%d",&first_list_items); //reads the address//
head1=insert_node(head1,first_list_items); // here declaring the first_list_items//
}
display_list(head1); //displaying list of header1//
printf("\nEnter the number of nodes in second list:"); //printing the node2 list of the console//
fflush(stdout);
scanf("%d",&second_list_nodes); //reads the address//
printf("\nEnter %d the elements:",second_list_nodes); //printing the list2 in the console//
for(int i=0;i < second_list_nodes;i++) //for loop will starts second_list_nodes here//
{
fflush(stdout);
scanf("%d",&second_list_items); //here declaring the second_list_items//
head2=insert_node(head2,second_list_items); //here declaring the second_list_items//
}
display_list(head2); //displaying the list of head1 and head2//
res_union = get_union(head1,head2); //result of the hard1 and head2 will store the memory of the same location//

#ifdef DEBUG_MAIN
printf("\nValue of Head1 and Head2 :%d %d\n",head1,head2); //debugging the console of the head1 and head2//
#endif
#ifdef DEBUG_MAIN
printf("\nvalue of Head1 and Head2 after performing union :%d %d\n",head1,head2);
printf("\nValue of res_union :%d\n",res_union);
#endif
printf("Here is the result of union:"); //end of the result will be display in the console//
display_list(res_union);
res_intersection=get_intersection(head1,head2); //result of the get intersection of head1 and head2//
#ifdef DEBUG_MAIN
printf("\nValue of Head1 and head2 after performing union :%d %d\n",head1,head2);
printf("\nValue of res_intersection :%d\n",res_intersection);
#endif
printf("\nHere is the result of intersection:"); //enfif is the final result will be display in the console//
display_list(res_intersection);

}

list.c

#include"list.h" //header//
void display_list(Node *head_ref) //displaying the list of the reference in the head//
{
if(head_ref==0) //here the condition is head_ref is equal to the 0//
{
printf(" list is empty"); //above the condition will be satisfied then the printf will be display//
}
else
{
tail=head_ref;
while(tail !=0) //while loop starts tail is not equal to the 0//
{
printf("%d", tail->data); //if condition is not satisfied then the else part will be display.after its will next list//

tail=tail->next;
}
tail=newnode;
}
}
Node *insert_node(Node *head_ref,int n) //insert the number of nodes//
{
printf("\nInserting Element at the beginning...\n"); //inserting the number of the elements in the console//
newnode=(Node*)malloc(sizeof(Node)); //here giving the size of the malloc node//
printf("Address of created newnode :%d\n",newnode); //printf is the printing address of the newnode//
newnode->data=n; //number of the newnode data//
printf("Inserted value is :%d\n",newnode->data); // inserted value of newnode data will be display on the console// newnode->next =head_ref; //here performing the next means loop will be created of the newnode data values//
head_ref=newnode; //reference of the newnode data is equal to head//
return head_ref; //return reference//
}
Node *get_union(Node *head_pointer1,Node *head_pointer2)//here node of pointer1 and pointer2 can be shared by the same memory location//
{
while(head_pointer1 !=0) //while loop starts head_pointer1 is not equal to the 0//
{
head_union= insert_node(head_union,head_pointer1->data); //inserting the data of the pointer1//
head_pointer1=head_pointer1->next; //its will go to the next of the value of new pointer next//
}
while(head_pointer2 !=0) //while loop starts head_pointer2 is not equal to the 0//
{
if(! compare(head_union,head_pointer2->data)) //here comparing the pointer1 and pointer2 of the data//
head_union=insert_node(head_union,head_pointer2->data); //inserting the data of the pointer2//
head_pointer2=head_pointer2->next; //its will go and take next of the value of new pointer2 next//
}
return head_union; //return union//
}
int compare(Node *head,int data) //compare the both *head data//
{
while(head != NULL) //while loop will start,here head is not equal to 0 is the condition//
{
if(head->data == data) //here head data is equal to data then shows the return 1//
return 1;
head = head->next; //here head is equal to next data then it will return zero//
}
return 0;
}
Node *get_intersection(Node *head_pointer1,Node*head_pointer2)//A set that consists of elements common will present in pointer1 and pointer2//
{
while (head_pointer1 !=0) //while loop will starts here head_ pointer is not equal to 0//
{
if(compare(head_pointer2,head_pointer1->data)) //here comparing both elements are same or not//
head_intersection = insert_node(head_intersection,head_pointer1->data); //inserting the data of the pointer1//
head_pointer1 = head_pointer1->next; //its will go and take next of the value of new pointer1 next//
}
return head_intersection;
}

List.h

#ifndef LIST_H_//preprocessor//
#define LIST_H_//preprocessor//
#include<stdio.h>//preprocessor//
#include<stdlib.h>//preprocessor//
#include<stdbool.h>//preprocessor//


typedef struct node//a new name for some existing data type//
{
int data;//local variable//
struct node *next;//declaration of the struct//
}Node;

static Node *head1,*head2,*head_union,*head_intersection,*newnode,*tail,*res_intersection,*res_union;//call the all function variable to header file//


Node *insert_node(Node *head_ref,int n);//call the function of insert_node//
void display_list(Node *head_ref);//display the reference//
Node *get_union(Node *head_pointer1,Node *head_pointer2);//call the all memeory location//
Node *get_intersection(Node *head_pointer1,Node *head_pointer2);//call the a set of variable/
int compare(Node *head,int data);//call the both node data//


#endif /* LIST_H_ * //end//

output:

Enter the number of nodes in first list:4

Enter 4 the elements:1 2 3 4

Inserting Element at the beginning...
Address of created newnode :11541560
Inserted value is :1

Inserting Element at the beginning...
Address of created newnode :11541576
Inserted value is :2

Inserting Element at the beginning...
Address of created newnode :11541592
Inserted value is :3

Inserting Element at the beginning...
Address of created newnode :11541608
Inserted value is :4
4321
Enter the number of nodes in second list:4

Enter 4 the elements:2 3 4 5

Inserting Element at the beginning...
Address of created newnode :11541624
Inserted value is :2

Inserting Element at the beginning...
Address of created newnode :11541728
Inserted value is :3

Inserting Element at the beginning...
Address of created newnode :11541744
Inserted value is :4

Inserting Element at the beginning...
Address of created newnode :11541760
Inserted value is :5
5432
Inserting Element at the beginning...
Address of created newnode :11541776
Inserted value is :4

Inserting Element at the beginning...
Address of created newnode :11541792
Inserted value is :3

Inserting Element at the beginning...
Address of created newnode :11541808
Inserted value is :2

Inserting Element at the beginning...
Address of created newnode :11541824
Inserted value is :1

Inserting Element at the beginning...
Address of created newnode :11540088
Inserted value is :5
Here is the result of union:51234
Inserting Element at the beginning...
Address of created newnode :11540104
Inserted value is :4

Inserting Element at the beginning...
Address of created newnode :11540120
Inserted value is :3

Inserting Element at the beginning...
Address of created newnode :11540136
Inserted value is :2

Here is the result of intersection:234

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.