Challenge

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

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

struct node{ //make struct node
int data;
struct node*next;

}*lone,*ltwo,*unionl,*intersectionl; //intialize four linkedlist
void initialize(){
lone=ltwo=NULL; //intialize lone and ltwo linked list null

}
void insert(struct node**head,int num){ //allot zeap memory and insert four linked list
struct node*newNode=(struct node*)malloc(sizeof(struct node));
newNode->data=num;
newNode->next=*head;
*head= newNode;
}
int search(struct node*head,int num){ //compare lone and ltwo linked list
while(head!=NULL){
if(head->data==num){
return 1;
}
head=head->next;
}
return 0;
}
struct node*findunion(struct node*lone,struct node*ltwo){ //find union linked list from lone and ltwo
unionl=NULL;
struct node*temp=lone;
while(temp!=NULL){
insert(&unionl,temp->data);
temp=temp->next;
}
while(ltwo!=NULL){
if(!search(lone,ltwo->data)){
insert(&unionl,ltwo->data);
}
ltwo=ltwo->next;
}
return unionl;
}

struct node* intersection(struct node* lone,struct node* ltwo) //find intersectionlinked list fron lone and ltow
{
intersectionl=NULL;
while(lone!=NULL)
{
if(search(ltwo,lone->data)){
insert(&intersectionl,lone->data);
}
lone=lone->next;

}
return intersectionl;
}
void printlinkedlist(struct node*nodeptr){ //print linked list
while(nodeptr!=NULL)
{
printf("%d",nodeptr->data);
nodeptr=nodeptr->next;
if(nodeptr != NULL)
printf("-->");
fflush(stdout);
}
}
int main(){
int i,lonecount,ltwocount,temp; //make four int variable
printf("enter the number of node in first linklist\n");
fflush(stdout);
scanf("%d",&lonecount); //scan the first linklist value
printf("enter %d integer\n",lonecount);
fflush(stdout);
for(i=0;i<lonecount;i++){
scanf("%d",&temp);
insert(&lone,temp); //make first linked list
}
printlinkedlist(lone); //print first linked list
printf("\nenter the number of node in second linklist\n");
fflush(stdout);
scanf("%d",&ltwocount); //scan second linked list value
printf("enter %d integer",ltwocount);
fflush(stdout);
for(i=0;i<ltwocount;i++){
scanf("%d",&temp);
insert(&ltwo,temp); //make second linked list
}
printlinkedlist(ltwo); //print second llinked list

findunion(lone,ltwo); // call find union
intersection(lone,ltwo); //call intersection
printf("\n print union linklist\n");
fflush(stdout);
printlinkedlist(unionl); //call printlinkedlist and print union linked list
printf("\n print intersection\n");
fflush(stdout);
printlinkedlist(intersectionl); //call printlinked list and print intersection linked list
}

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.