Challenge

Project 1 - 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:

1.Here, user given the First linked list quantity of data like 4.

2.Then user provide the sset of data of First list=[2,3,4,5].

3.They given the Second linked list quantity of data like 4.

4.Then user provide the sset of data of First list=[3,4,5,6].

5.After that we can apply the union and intersection of these data First list, Second list.

Goals:

1.Implementation of interface for mathematical set theory using c programming.

2.Giving two list of data as input to get the output as union & intersection for Given list of data.

3.Union and intersection do from the given two set of data.

Key highlights of the project:

1. Creating two linked list of data using single linked list.

2. Insertion is using for insert the data from one data to another data accordingly.

3. Intersection is identify or taken the elements which are present same in both lists.

4. All the elements that are in at least one of the two list.

Deliverable of the Project:

1. Intersection is identify the same element of both First and Second list.

2. Here, interestion is indenty the 5,4,3 data is common in both the list.

3. Union it's help to arrange all the data from top to bottom order with help of two list. But it will not take 2 same data in both the list, it will take only data.

4. Here, union is arrange the both list :6,5,4,3,2.

Expected outcomes:

1. Here using single linked list, it is the simplest form of a linked list.

2. Linked list ia a linear data structure contain a collection of data elements called nodes.

3. Intersection data, traverse through the first list, and look for every element in the second list. If the element is present in the second list, then add that element to the result list.

4. Union data, traverse through the first list and add all of its elements to the result list. Now, traverse through the second list. If an element of the second list is already present in the result list.

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


 //Preprocessor


//....Defining the Node....
typedef struct Node
{
int data;
struct Node *Next;

} Node; //User define data typedef declaration

// Static Variables Declaration
static Node *temp1,*temp2,*First_node,*Second_node,*First_newnode,*Second_newnode,*find_intersection,*find_union,*newnode,*head_intersection,*head_union;

// This function is creating for inserting the elements to linked list
Node *insert_node(Node *head_ref,int n)
{

newnode=(Node*)malloc(sizeof(Node)); //allocation of memory
newnode->data = n;
newnode->Next=head_ref;
head_ref=newnode;
return head_ref;
}

// This function is creating for compare two different linked list
int compare(Node *head, int data)
{
while(head != NULL)
{
if(head->data==data)
return 1;
head=head->Next;
}
return 0;
}

// This function is creating for to get the Union elements
Node *get_union(Node *head_pointer1, Node *head_pointer2)
{
Node *temp = head_pointer1; //created for temporary value is equal to pointer 1
while(temp != 0) //check whether the head pointer is not equal to 0 or NULL
{

head_union=insert_node(head_union,temp->data);
temp=temp->Next;
}
while(head_pointer2 != 0)
{
if (!compare(head_pointer1, head_pointer2->data))
head_union = insert_node(head_union,head_pointer2->data);
head_pointer2 = head_pointer2->Next;
}
return head_union;
}

//This function is Creating for to get the Intersection elements //
Node *get_intersection(Node *head_pointer1,Node *head_pointer2)
{
while(head_pointer1 != 0)//check whether the head pointer is not equal to 0 or NULL//
{
if (compare(head_pointer2, head_pointer1->data))
head_intersection=insert_node(head_intersection,head_pointer1->data);
head_pointer1=head_pointer1->Next;
}
return head_intersection;
}

//Prints a linked list from first node to last node
void print_LinkedList(Node *nodePtr)
{
while (nodePtr != NULL)
{
printf("%d", nodePtr->data);
nodePtr = nodePtr->Next;
if(nodePtr != NULL)
printf("-->");
}
}

int main() //Main function
{
int x,y,i; // local variables Declaration

// Allocation of memory in heap.
temp1 = malloc(sizeof(Node));
temp2 = malloc(sizeof(Node));

// Asking to user to enter the number of elements of 1st linked list.
printf("Enter the Number of elements of First linked list\n");
fflush(stdout);
scanf("%d",&x);

// Asking to user to enter the items of 1st linked list.
printf("Enter the items of First linked list:\n");
fflush(stdout);
scanf("%d",&temp1->data);
temp1->Next = NULL;

First_node = temp1; // Creating 1st linked list
for(i = 1; i < x; i++)
{
First_newnode = malloc(sizeof(Node));
fflush(stdout);
scanf("%d",&(First_newnode->data));
First_newnode->Next = NULL;
First_node->Next = First_newnode;
First_node = First_node->Next;
}

First_node = temp1; // Printing the elements of 1st linked list
printf("You entered the First linked list:\n");
{
print_LinkedList(First_node);
}

// Asking user to enter the number of elements of 2nd linked list
printf("\nEnter the Number of elements of Second linked list\n");
fflush(stdout);
scanf("%d",&y);

// Asking to user to enter the items of 2nd linked list.
printf("Enter the items of second linked list:\n");
fflush(stdout);
scanf("%d",&temp2->data);
temp2->Next = NULL;

Second_node = temp2;
for(i = 1; i < y; i++) // Creating 2nd linked list
{
Second_newnode = malloc(sizeof(Node));
fflush(stdout);
scanf("%d",&(Second_newnode->data));
Second_newnode->Next = NULL;
Second_node->Next = Second_newnode;
Second_node = Second_node->Next;
}

Second_node = temp2; // Printing elements of 2nd linked list
printf("You entered Second linked list:\n");
{
print_LinkedList(Second_node);
}

// Union of both linked list
find_union = NULL;
{
printf("\nUnion of First and Second linked list\n");
}
find_union = get_union(First_node,Second_node);
print_LinkedList(head_union);

// Intersection of both linked list
find_intersection = NULL;
{
printf("\nIntersection of First and Second linked list\n");
}

find_intersection = get_intersection(First_node,Second_node); // calling get_intersection function

if(find_intersection == 0) //if there is no common items in both list
{
printf("First and Second linked list not have common items");
}
print_LinkedList(head_intersection);

return 0;
}
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.