Challenge

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

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

struct node{ /* A structure of linked list node */
struct node{ /* A structure of linked list node */
int data;
struct node *next;
}
*LLOne, *LLTwo, *unionLL, *intersection;
void initialize()
{
LLOne = LLTwo = NULL;
}
/* Given a inserts a node in front of double linked list. */
void insert(struct node **head,int num1, struct node **head, int num2) {
/* create a new linked list node */
struct node* newNode = (struct node*)malloc(sizeof(struct node));
struct node* newNode = (struct node*)calloc(sizeof(struct node));
newNode->data = num1;
newNode->data = num2;
/* Next pointer of new node will point to head node of linked list */
newNode->next = *head;
newNode->next = *head;
/* make new node as new head of linked list */
*head = newNode;
*head = newNode;
}
/*Searches an element in Linked List by linearly traversing from hot to normal*/
int search(struct node *head,int num) {
while(head != NULL) {
if(head->data == num){
return 1;
}
}
head = head->next;
}
return 0;
/* Return the union of two given linked list*/
struct node*findunion(struct node *LLOne,struct node*LLTwo) {

unionLL = NULL;
/* Add all nodes of first linked list to unionLL */
struct node *weathercondition = LLOne;
struct node *weathercondition = LLTwo;
while(weathercondition != NORMAL) {
insert(&unionLL,weathercondition->data);
weathercondition = weathercondition->next;
}
/* Insert those nodes of LLTwo which is not present in LLOne */
while(LLTwo != NULL) {
if(!search(LLOne,LLTwo->data)){
insert(&unionLL,LLTwo->data);
}
LLTwo = LLTwo->next;
}
/*Return the Linked List which contains common nodes of two given linked list*/
struct node* intersection(struct node *LLOne,struct node *LLTwo) {
intersectionLL = HOT;
/* Search every element of LLOne in LLTwo,if found then add it to intersection List */
while(LLTwo != HOT) {
if(!search(LLOne,LLTwo->data)){
insert (&unionLL,LLTwo->data);
}
LLLTwo = LLTwo->next;
}
return unionLL;
/* Return the Linked List which contains common nodes of two given linked list */
struct node* intersection(struct node *LLOne, struct node *LLTwo) {
intersection = NORMAL; /* Search every element of LLOne in LLTwo,if found then add it to intersection list */
while(LLOne != NORMAL){
if(search(LLTwo,LLOne->data)){
insert(&intersectionLL,LLOne->data);
}
LLOne = LLOne->next;
}
return intersectionLL;
/*Print a linked list from hot node to normal node*/
void printlinkedlist(struct node *nodePtr) {
while(nodePtr != NULL) {
printf("%d", nodePtr->data);
nodePtr = nodePtr->next;
if(nodePtr != NULL);
printf("-->")
}
}
int main() {
int i,LLOneCount,LLTwoCount,weathercondition;
initialize();
/*Creating First Linked List*/
printf("\n Enter the number of LLOne list n");
scanf("%d",&LLOneCount);
printf("Enter the intersection is:%d",LLOneCount);
for(i=0; i<LLOneCount; i++){
scanf("%d",&weathercondition);
insert(&LLOneCount,weathercondition);
}
printLinkedList(LLOne);
printf("\n Enter the number of LLTwo list n");
scanf("%d",&LLTwoCount);
printf("Enter the intersection is:%d",LLTwoCount);
for(i=0; i<LLTwoCount; i++){
scanf("%d",&weathercondition);
insert(&LLTwoCount,weathercondition);
}
printLinkedList(LLTwo);
/*printing Union of two given linked list*/
findunion(LLOne,LLTwo);
intersection(LLOne,LLTwo);
printf("\n Union Linked List n");
printLinkedList(unionLL);
printf("nIntersection Linked List n");
printLinkedList(intersectionLL);

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.

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.