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
#include

#define MAX_SIZE 100

// function to find the union of two lists
int *findUnion(int *list1, int size1, int *list2, int size2, int *size3) {
int *result = (int *)malloc(MAX_SIZE * sizeof(int));
int i, j, k;
*size3 = 0;

// loop through both lists and add each unique element to the result array
for(i = 0; i < size1> for(j = 0; j < size2> if(list1[i] == list2[j]) {
break;
}
}
if(j == size2) {
result[*size3] = list1[i];
(*size3)++;
}
}
for(k = 0; k < size2> result[*size3] = list2[k];
(*size3)++;
}

return result;
}

// function to find the intersection of two lists
int *findIntersection(int *list1, int size1, int *list2, int size2, int *size3) {
int *result = (int *)malloc(MAX_SIZE * sizeof(int));
int i, j, k;
*size3 = 0;

// loop through both lists and add each common element to the result array
for(i = 0; i < size1> for(j = 0; j < size2> if(list1[i] == list2[j]) {
result[*size3] = list1[i];
(*size3)++;
break;
}
}
}

return result;
}

int main() {
int size1, size2, size3, i;
int list1[MAX_SIZE], list2[MAX_SIZE], *unionList, *intersectionList;

printf("Enter size of list 1: ");
scanf("%d", &size1);
printf("Enter �lements of list 1:\n", size1);
for(i = 0; i < size1> scanf("%d", &list1[i]);
}

printf("Enter size of list 2: ");
scanf("%d", &size2);
printf("Enter �lements of list 2:\n", size2);
for(i = 0; i < size2> scanf("%d", &list2[i]);
}

unionList = findUnion(list1, size1, list2, size2, &size3);
printf("Union of the two lists is:\n");
for(i = 0; i < size3> printf("%d ", unionList[i]);
}
printf("\n");
free(unionList);

intersectionList = findIntersection(list1, size1, list2, size2, &size3);
printf("Intersection of the two lists is:\n");
for(i = 0; i < size3> printf("%d ", intersectionList[i]);
}
printf("\n");
free(intersectionList);

return 0;
}

#include
#include

#define MAX_SIZE 100

// function to find the union of two lists
int *findUnion(int *list1, int size1, int *list2, int size2, int *size3) {
int *result = (int *)malloc(MAX_SIZE * sizeof(int));
int i, j, k;
*size3 = 0;

// loop through both lists and add each unique element to the result array
for(i = 0; i < size1> for(j = 0; j < size2> if(list1[i] == list2[j]) {
break;
}
}
if(j == size2) {
result[*size3] = list1[i];
(*size3)++;
}
}
for(k = 0; k < size2> result[*size3] = list2[k];
(*size3)++;
}

return result;
}

// function to find the intersection of two lists
int *findIntersection(int *list1, int size1, int *list2, int size2, int *size3) {
int *result = (int *)malloc(MAX_SIZE * sizeof(int));
int i, j, k;
*size3 = 0;

// loop through both lists and add each common element to the result array
for(i = 0; i < size1> for(j = 0; j < size2> if(list1[i] == list2[j]) {
result[*size3] = list1[i];
(*size3)++;
break;
}
}
}

return result;
}

int main() {
int size1, size2, size3, i;
int list1[MAX_SIZE], list2[MAX_SIZE], *unionList, *intersectionList;

printf("Enter size of list 1: ");
scanf("%d", &size1);
printf("Enter �lements of list 1:\n", size1);
for(i = 0; i < size1> scanf("%d", &list1[i]);
}

printf("Enter size of list 2: ");
scanf("%d", &size2);
printf("Enter �lements of list 2:\n", size2);
for(i = 0; i < size2> scanf("%d", &list2[i]);
}

unionList = findUnion(list1, size1, list2, size2, &size3);
printf("Union of the two lists is:\n");
for(i = 0; i < size3> printf("%d ", unionList[i]);
}
printf("\n");
free(unionList);

intersectionList = findIntersection(list1, size1, list2, size2, &size3);
printf("Intersection of the two lists is:\n");
for(i = 0; i < size3> printf("%d ", intersectionList[i]);
}
printf("\n");
free(intersectionList);

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.