Challenge

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

step1 preparing two linked list and entreing the values

step2 creating the new linked list

step3 searching /union / intersection operation on series

step4 calling void function using switch case to chose the operation

#include <stdio.h>
#include <stdlib.h>
struct node
{
int data;
struct node *next;
};
typedef struct node node;

node *dataone,*datatwo,*unionl,*intersectionl;
void initialize()
{
dataone = datatwo =NULL;
}
void insert(node* *head,int num)
{
node * newnode=(node*)malloc(sizeof(node));
newnode->data=num;
newnode->next=*head;
*head=newnode;
}
int search(node *head,int num)
{
while (head != NULL)
{
if(head->data == num)
{
return 1;
}
head = head->next;
}
return 0;
}
void findunion(node *dataone,node *datatwo)
{
unionl = NULL;
node *temp = dataone;
while(temp!=NULL)
{
insert(&unionl,temp->data);
temp=temp->next;
}
while(datatwo!=NULL)
{
if(!search(dataone,datatwo->data))
{
insert(&unionl,datatwo->data);
}
datatwo=datatwo->next;
}

}

void intersection(node *dataone,node *datatwo)
{
intersectionl=NULL;
while(dataone!=NULL)
{
if(search(datatwo,dataone->data))
{
insert(&intersectionl,dataone->data);
}
dataone=dataone->next;
}

}
void displaylist(struct node *temp2)
{
while(temp2!=NULL)
{
printf("%d",temp2->data);
temp2=temp2->next;
if(temp2!=NULL)
printf("-->");
}

}
int main()
{
//initialize();
int i,j,nodeone,nodetwo,temp,choice;
newlinkedlist:
printf("\n enter the node in link list one :");
fflush(stdout);
scanf("%d",&nodeone);
printf("\n enter the node in link list two :");
fflush(stdout);
scanf("%d",&nodetwo);
printf("\n entre the data i link list %d :",nodeone);
fflush(stdout);
for(i=0;i<nodeone;i++)
{
scanf("%d",&temp);
insert(&dataone,temp);
}

printf("\n entre the data link list 2 %d :",nodetwo);
fflush(stdout);
for(j=0;j<nodetwo;j++)
{
scanf("%d",&temp);
insert(&datatwo,temp);
}
while(1){
printf("\n entre the choice \n");
fflush(stdout);
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("\n linked list one \n");
displaylist(dataone);
break;
case 2:
printf("\n linked list one \n");
displaylist(datatwo);
break;
case 3:
printf("\n union of the link list\n");
findunion(dataone,datatwo);
displaylist(unionl);
break;
case 4:
printf("\n intersection of list\n");
intersection(dataone,datatwo);
displaylist(intersectionl);
break;
case 5:
goto newlinkedlist;
}
}

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.