Update DS/C/Lab/Week8/DLLUnionIntersec.c

This commit is contained in:
Aadit Agrawal 2024-10-15 10:59:49 +05:30
parent d15b9d0359
commit 8e68c6a751

View File

@ -1,5 +1,3 @@
// Write a program to implement union and intersection of two doubly linked lists.
#include <stdio.h>
#include <stdlib.h>
@ -88,3 +86,36 @@ void display(NODE head) {
}
printf("\n");
}
int main() {
NODE list1 = NULL;
NODE list2 = NULL;
// Inserting elements into list1
insert_rear(&list1, 1);
insert_rear(&list1, 2);
insert_rear(&list1, 3);
// Inserting elements into list2
insert_rear(&list2, 3);
insert_rear(&list2, 4);
insert_rear(&list2, 5);
// Displaying the lists
printf("List 1: ");
display(list1);
printf("List 2: ");
display(list2);
// Union of the lists
NODE union_result = union_lists(list1, list2);
printf("Union: ");
display(union_result);
// Intersection of the lists
NODE intersection_result = intersection_lists(list1, list2);
printf("Intersection: ");
display(intersection_result);
return 0;
}