All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
Code- /* * Project_1.c * * Created on: 26-Aug-2022 * Author: Viraj */ #include #include // A structure of linked list nodestruct node { int value; struct node *next; } *SetOne, *SetTwo, *SetUnion, *SetIntersection; void initialize() { SetOne = SetTwo = NULL;} void insert(struct node **head, int num) { // Create a new Linked…
Viraj Brid
updated on 01 Oct 2022
Code-
/*
* Project_1.c
*
* Created on: 26-Aug-2022
* Author: Viraj
*/
#include
#include
// A structure of linked list node
struct node
{
int value;
struct node *next;
} *SetOne, *SetTwo, *SetUnion, *SetIntersection;
void initialize()
{
SetOne = SetTwo = NULL;
}
void insert(struct node **head, int num)
{
// Create a new Linked List node
struct node* newNode = (struct node*) malloc(sizeof(struct node));
newNode->value = num;
// Next pointer of new node will point to head node of linked list
newNode->next = *head;
//make new node as new head of linked list
*head = newNode;
}
// Searches an element in Linked List by linearly traversing from head to tail
int search(struct node *head, int num)
{
while (head != NULL)
{
if (head->value == num)
{
return 1;
}
head = head->next;
}
return 0;
}
//Returns the union of two given linked list
struct node* funcUnion(struct node *SetOne, struct node *SetTwo)
{
SetUnion = NULL;
// Add all nodes of first set
struct node *temp = SetOne;
while(temp != NULL)
{
insert(&SetUnion, temp->value);
temp = temp->next;
}
// Insert those nodes of set 2 which is not present in set 1
while(SetTwo != NULL)
{
if(!search(SetOne, SetTwo->value))
{
insert(&SetUnion, SetTwo->value);
}
SetTwo = SetTwo->next;
}
return SetUnion;
}
//Returns the Linked List which contains common elements from two sets
struct node* intersection(struct node *SetOne, struct node *SetTwo)
{
SetIntersection = NULL;
//Search every element of SetOne in SetTwo, If found then add it to intersection List
while(SetOne != NULL)
{
if(search(SetTwo, SetOne->value))
{
insert(&SetIntersection, SetOne->value);
}
SetOne = SetOne->next;
}
return SetIntersection;
}
//Prints a linked list from head node till tail node
void printSets(struct node *ptr)
{
while (ptr != NULL)
{
printf("%d\t", ptr->value);
ptr = ptr->next;
}
}
int main()
{
int i, n1, n2, temp;
initialize();
//Creating First Set
printf("\nEnter number of elements in first Set:\n");
fflush(stdout);
scanf("%d", &n1);
for(i=0; i
{
printf("Enter The element %d of set 1:",(i+1));
fflush(stdout);
scanf("%d", &temp);
insert(&SetOne, temp);
}
printf("\nThe first set is as follow\n");
printf("-----------------------------------------\n");
printSets(SetOne);
//Creating Second Set
printf("\n\nEnter number of Elements in second set:\n");
fflush(stdout);
scanf("%d", &n2);
for(i=0; i
{
printf("Enter The element %d of set 2:",(i+1));
fflush(stdout);
scanf("%d", &temp);
insert(&SetTwo, temp);
}
printf("\nThe second set is as follow\n");
printf("-----------------------------------------\n");
printSets(SetTwo);
//printing Union of given two sets
funcUnion(SetOne, SetTwo); //Function call
printf("\n\n\nThe Union of sets is as follow\n");
printf("-----------------------------------------\n");
printSets(SetUnion);
//printing intersection of given two sets
intersection(SetOne, SetTwo);
printf("\n\n\nThe Intersection of sets is as follow\n");
printf("-----------------------------------------\n");
printSets(SetIntersection);
return 0;
}
Result 1-

Result 2-

Leave a comment
Thanks for choosing to leave a comment. Please keep in mind that all the comments are moderated as per our comment policy, and your email will not be published for privacy reasons. Please leave a personal & meaningful conversation.
Other comments...
Project 1 - Creation of user defined data type to implement the user interfaces for working with ‘Set’ (Mathematical Set theory) using Linked List
Code- /* * Project_1.c * * Created on: 26-Aug-2022 * Author: Viraj */ #include #include // A structure of linked list nodestruct node { int value; struct node *next; } *SetOne, *SetTwo, *SetUnion, *SetIntersection; void initialize() { SetOne = SetTwo = NULL;} void insert(struct node **head, int num) { // Create a new Linked…
06 Oct 2022 05:22 AM IST
Project 1 - Creation of user defined data type to implement the user interfaces for working with ‘Set’ (Mathematical Set theory) using Linked List
Code- /* * Project_1.c * * Created on: 26-Aug-2022 * Author: Viraj */ #include #include // A structure of linked list nodestruct node { int value; struct node *next; } *SetOne, *SetTwo, *SetUnion, *SetIntersection; void initialize() { SetOne = SetTwo = NULL;} void insert(struct node **head, int num) { // Create a new Linked…
01 Oct 2022 12:30 PM IST
Project 2 - Development of TFT Cluster Speedometer Software Component
Development of TFT Cluster Speedometer Software Component Cluster Instrument receives the signals from other ECU via CAN bus interface. It also receives commands from the driver via steering wheel buttons. The signals are then processed by the Cluster ECU, after which the Cluster ECU may send the vehicle information…
28 Sep 2022 07:05 PM IST
Project 1 - Wiper control system and Vehicle speed calculation for ABS using Wheel Speed sensor
Q1)Develop Simulink/state flow model for wiper control system based on the given conditions. Description of Challenge: If the density of the rain is low, then wiper rotates with low speed & the output signal should be 100rpm If the density of the rain is medium, then wiper rotates with medium speed & the…
25 Sep 2022 01:14 PM IST
Related Courses
0 Hours of Content
Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.
© 2025 Skill-Lync Inc. All Rights Reserved.