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 {
int data;
struct node *next;
};
int i;
struct node* createlist( )
{
int n;
struct node *head=NULL,*p,*ptr;
int x,i;
printf("enter no of elements in list : \n");
fflush(stdout);
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("enter the data value: ");
fflush(stdout);
scanf("%d",&x);
p=(struct node*)malloc(sizeof(struct node));
p->data=x;
p->next=NULL;
if(head==NULL){
head=ptr=p;
}
else
{
ptr->next=p;
ptr=p;
}
}
return head;
}
void displaylist(struct node *list)
{
struct node *p;
p=list;
while(p!=0)
{
printf("%d ", p->data);
p=p->next;
}
}
int intersecn(struct node *list1, struct node *list2)
{
printf("\nIntersection list:\t");
fflush(stdout);
struct node *temp3 = list1;
struct node *temp4 = list2;
while (temp3) {
while (temp4) {
if (temp3->data == temp4->data)
{
printf("%d \t ", temp3->data);
}
temp4 = temp4->next;
}
temp3 = temp3->next;
temp4 = list2;
}
return 0;
}
int unin(struct node *list1,struct node *list2)
{
printf("\nUnion list: \t ");
fflush(stdout);
struct node *temp3 = list1;
struct node *temp4 = list2;
int flag=1;
displaylist(temp3);
while(temp4)
{ if(temp3->data!=temp4->data)
{
printf("%d",temp4->data);
}
temp4 = temp4->next;
}
return 0;
}
int main()
{
struct node *list1,*list2 ;
list1=list2=NULL;
printf("list 1:\n");
list1=createlist();
printf("list 2:\n");
list2=createlist();
printf("\nlist 1 is : ");
displaylist(list1);
printf("\nlist 2 is : ");
displaylist(list2);
intersecn(list1,list2);
unin(list1,list2);
}

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.