Challenge

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

The c code is given below

/*
 * project1.c
 *
 *  Created on: Feb 18, 2023
 *      Author: hp
 */

#include
#include
//structure of node

struct node{
	int data;
	struct node *next;

}*LLone,*LLtwo,*LLunion,*LLintersection;

void initialize() //function to initializing NULL
{
	LLone=NULL;
	LLtwo=NULL;

}

void insert(struct node **head, int num)  //function to insert a node
{
	struct node*newnode=(struct node*)malloc(sizeof(struct node));  //inserting new node using maolloc
	newnode->data=num;
	newnode->next=*head; //the next of the new node is set as head
	*head=newnode; //the head pointer of the linked list is updated to point the new node
}
int search(struct node *head, int num) //searching using traversing
{
	while(head!=NULL)
	{
		if(head->data==num)
		{
			return 1;
		}
		head=head->next;
	}

		return 0;
}
struct node*findunion(struct node* LLone, struct node*LLtwo)  //function for union
		{
	LLunion=NULL;
	struct node *temp=LLone;
	while(temp!=NULL)
	{
		insert(&LLunion,temp->data);  //function call for insert
		temp=temp->next;
	}
	while(LLtwo!=NULL)
	{
		if(!search(LLone,LLtwo->data))
		{
		insert(&LLunion,LLtwo->data); //function call for insert
		}
		LLtwo=LLtwo->next;
	}
	return LLunion;
		}
struct node*findintersection(struct node* LLone, struct node* LLtwo) //function for intersection
{
	LLintersection=NULL;
	while(LLone!=NULL)
	{
		if(search(LLtwo,LLone->data))  //function call for search function
		{
		insert(&LLintersection,LLone->data); //function call for insert
		}
		LLone=LLone->next;
	}


		return LLintersection;
}
void printLL(struct node*nodeptr)  //function for printing
{
	while(nodeptr!=NULL)
	{
		printf("%d",nodeptr->data);
		nodeptr=nodeptr->next;
		if(nodeptr!=NULL)
		{
			printf("-->");
		}
	}
}
int main()   //main function
{
	int i,LLonecount,LLtwocount,temp;  //initializing variables
	initialize();
	printf("\n enter the number of nodes in the first linked list");
	fflush(stdout);
	scanf("%d",&LLonecount);
	printf("\n enter %d integers",LLonecount);
	fflush(stdout);
	for(i=0;i

The screenshot of the result is given below

also the .c file is attached below

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.