Challenge

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

FIRST PROJECT

#include <stdio.h>
#include<stdlib.h>
#include<stdbool.h>
struct Node
{
int data;
struct Node* nextptr;
};


void push(struct Node **vyshu, int new_data);

bool IsPresent(struct Node *station, int data);

struct Node *getUnion(struct Node *station1,struct Node *station2)
{
struct Node *temp = NULL;
struct Node *temp1 = station1, *temp2 = station2;


while (temp1 != NULL)
{
push(&temp,temp1->data);

temp1 = temp1->nextptr;
}

while (temp2 != NULL)
{
if (!IsPresent(temp,temp2->data))

push(&temp,temp2->data);

temp2 = temp2->nextptr;
}

return temp;
}

struct Node *getIntersection(struct Node* station1, struct Node* station2)
{
struct Node* temp = NULL;
struct Node* temp1=station1;

while(temp1 != NULL)

{
if(IsPresent(station2,temp1->data))

push(&temp,temp1->data);

temp1=temp1->nextptr;
}
return temp;

}
void push(struct Node **Vyshu, int new_data)
{
struct Node* stage = (struct Node*)malloc(sizeof(struct Node));

stage->data = new_data;

stage -> nextptr = *Vyshu;

*Vyshu=stage;
}
void printList(struct Node* Jaga)
{
while(Jaga != NULL)
{
printf("%d",Jaga -> data);

Jaga = Jaga -> nextptr;
}
}
bool IsPresent(struct Node* station, int data)
{
struct Node* t=station;

while(t !=NULL)
{
if(t->data == data)

return 1;

t=t->nextptr;
}
return 0;
}


int main()
{
struct Node* station1=NULL;
struct Node* station2=NULL;
struct Node* Union=NULL;
struct Node* Intersection=NULL;

push(& station1 , 5);

push(& station1 , 4);

push(& station1 , 7);

push(& station1 , 3);

push(& station1 , 9);


push(& station2 , 3);

push(& station2 , 9);

push(& station2 , 5);

push(& station2 , 8);

push(& station2 , 2);

Union= getUnion(station1,station2);

Intersection = getIntersection(station1,station2);

printf("\n First : ");
printList(station1);
printf("\n");

printf("\n Second : ");
printList(station2);
printf("\n");

printf("\n Union : ");
printList(Union);
printf("\n");

printf("\n Intersection : ");
printList(Intersection);
printf("\n");

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.