Challenge

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

/*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>
//creating the refferntial structure / Blue-print of a node.
struct nd{
int dt;
struct nd *nxt;
} *lone , *stwo ,*un ,*itsec;
//Intialising both linked list one and two.
void insl(){
lone = stwo = NULL;
}
//Function for insertion of list elements to the node of linked list.
void insert(struct nd **hd,int nm){
struct nd *nend = (struct nd*)malloc(sizeof(struct nd));
nend->dt = nm;
nend->nxt = *hd;
*hd = nend;
}
//searching the same elments in the list.
int search(struct nd *hd,int nm){
while(hd != NULL){
if(hd->dt == nm){
return 1;
}
hd = hd->nxt;
}
return 0;
}
//function for union of two linked lsit and merge
//and print the elements without reducncy.
//exp:- l1 - 1->2->3.
//l2 - 3-> 4.
// union - 1->2->3->4.
struct nd *findun(struct nd *lone , struct nd *stwo){
un = NULL;
struct nd *temp = lone;
while(temp != NULL){
insert(&un,temp->dt);
temp = temp->nxt;
}
while(stwo != NULL){
if(!search(stwo,stwo->dt)){
insert(&un,stwo->dt);
}
stwo = stwo->nxt;
}
return un;
}
//Function for intersection
/*Like l1 exp:- l1 - 1->2->3.
l2 - 3-> 4.
intersection:- 3*/
struct nd *insec(struct nd *lone, struct nd *stwo){
itsec = NULL;
while(lone != NULL){
if(search(stwo,lone->dt)){
insert(&itsec,lone->dt);
}
lone = lone->nxt;
}
return itsec;
}
//function for printing linked list
void printlnk(struct nd *ndpt){
while(ndpt != NULL){
printf("%d",ndpt->dt);
ndpt = ndpt->nxt;
if(ndpt != NULL){
printf("--->");
}
}
printf(".");
}

int main(){
int i , lonc , stc , temp;
insl();
printf("\nEnter the count for List one:- ");
scanf("%d",&lonc);
printf("\nEnter the %d elments to List one:- ",lonc);
for(i = 0 ; i<lonc ; i++){
scanf("%d",&temp);
insert(&lone,temp);
}
printlnk(lone);
printf("\nEnter the count for List second:- ");
scanf("%d",&stc);
printf("\nEnter the %d elments to List second:- ",stc);
for(i = 0 ; i<stc ; i++){
scanf("%d",&temp);
insert(&stwo,temp);
}
printlnk(stwo);

findun(lone,stwo);//passing lone,stwo for union.
insec(lone,stwo);//passing lone,stwo for intersection.
printf("\nUnion of One & Two list :- ");
printlnk(un);
printf("\nIntersecction of One and Two List:- ");
printlnk(itsec);

return 0;
}
OUTPUT:-


Enter the count for List one:- 4

Enter the 4 elments to List one:- 1 2 3 4
4--->3--->2--->1.
Enter the count for List second:- 3

Enter the 3 elments to List second:- 3 4 5
5--->4--->3.
Union of One & Two list :- 1--->2--->3--->4.
Intersecction of One and Two List:- 3--->4.

SCREENSHOT:-

NOTE:- Hey! Skill-link grader, actually to complete this project, I took help from online resources to get a basic knowledge, and I ensure that I have an idea of how this code actually works.

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.