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 // self referencing structure for linked list
{
int data ;
struct node* next;
};

// defined two arrays for union and intersection results
int uni_count = 0;
int int_elements[100];
int unin_elements[100];
// function for print the result
void toprint(struct node*,int);
//functions for intersection and union opeartion
void store_intersection_elements(int,int);
void store_union_elements(int);

int main()
{ //int i = 0;

struct node node1,node2,node3,node4,node5,node6;
struct node* header1 = &node1;
struct node* header2 = &node4;
node1.data = 1;
node1.next = &node2;
node2.data = 2;
node2.next = &node3;
node3.data = 3;
node3.next = NULL;
node4.data = 3;
node4.next = &node5;
node5.data = 2;
node5.next = &node6;
node6.data = 5;
node6.next = NULL;
int i = 0 ;int j= 0;
toprint(header1,1);
toprint(header2,2);
while((header1 != NULL)){
store_union_elements(header1->data);
header2 = &node4;

while ((header2 != NULL) )
{
if (header1->data == header2->data)
{
//printf("print 1 linked list current data to intersection %d\n",header1->data);

store_intersection_elements(header1->data,i);
i++;}

else{
j++;
store_union_elements(header2->data);}

header2 = header2->next;


}// inner loop for compare the each 1st linkedlist elements with second list

header1 = header1->next;
j++;
}//to change the first linked list elements


printf("\nprint of intersection elements\n"); // to print interection elements
int k = 0;
for(k;k <= i--;k++){
printf("%d ",int_elements[k]);
}// loop for print the intersection elements

printf("\nprint of union elements\n");// print the union elements
k = 0;
for(k;k <= uni_count-1 ;k++){
printf("%d ",unin_elements[k]);
}// loop for printing the union elements
return 0;
}

void store_intersection_elements(int data,int indx)// function for store the intersection elements
{
int_elements[indx] = data;
}

void store_union_elements(int data){
int temp = 0;
for(temp; temp <= uni_count; temp++){
if( unin_elements[temp] == data){
return;
}
}
unin_elements[uni_count] = data;
uni_count++;
}// function for union elements


void toprint(struct node* header_print,int a)
{ printf("\nData of %d linked list\n",a);
while (header_print != NULL)
{
printf("%d ",header_print->data);
header_print = header_print->next ;
}//loop for print the elements present in linkedlist
}

OUTPUT:

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.