Challenge

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

#include

#include

struct node

{

int data;

struct node *next;

} *LLone, *LLtwo, *unionLL, *intersectionLL;

void initialize()

{

LLOne=LLtwo=NULL;

}

void insert(struct node**head, int num)

{

struct node* newnode=(struct node*)

malloc(sizeof(struct node));

newnode->data = num;

newnode->next = head;

*head=newnode;

}

int search(struct node*head, int num)

{

while(head!=NULL)

{

if(head->data==num)

{

return 1;

}

head = head->next;

}

return 0;

}

struct node* findunion(struct node*LLone, struct node*LLtwo)

{

unionLL = NULL;

struct node *temp= LLone;

while(temp !=NULL)

{

insert(&unionLL,tepm->data);

temp=temp->next;

}

while(LLtwo !=NULL)

{

if(!search(LLone,LLtwo->data))

{

insert(&unionLL,LLtwo->data);

}

LLtwo=LLtwo->next;

}

return unionLL;

}

struct node* intersection(struct node *LLone,struct node *LLtwo)

{

intersectionLL = NULL;

while(LLone !=NILL)

{

if(!search(LLtwo,LLone->data))

{

insert(&intersectionLL, LLone->data);

}

LLone = LLone->next;

}

return intersectionll;

}

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, temp;

initialize();

printf("enter number of nodes in first linked listn");

scanf("%d", &LLonecount);

printf("enter %d integersn", LLonecount);

for(i=0; i<LLonecount; i++)

{

scanf("%d", &temp);

insert(&LLone, temp);

}

printlinkedlist(LLone);

printf("n enter number of nodes in second linked listn");

scanf("%d", &LLtwocount):

printf("enter %d integersn:, LLtwocount);

for(i=0; i<LLtwocount; i++)

{

scanf("%d", &temp);

insert(&LLtwo, temp);

}

printlinkedlist(LLtwo);

findunion(LLone, LLtwo);

intersection(LLone, LLtwo);

printf("n union linked listn");

printlinkedlist(unionLL);

printf("n intersection linked listn");

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.