Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdbool.h>
- #include <stdlib.h>
- typedef struct list_node_s {
- int value;
- struct list_node_s *next;
- } list_node_t;
- list_node_t *subtraction(list_node_t *head1, list_node_t *head2) {
- list_node_t *new_head, *new_ptr, *new_current;
- for (list_node_t *ptr1 = head1; ptr1 != NULL; ptr1 = ptr1->next) {
- bool found = false;
- for (list_node_t *ptr2 = head1; ptr2 != NULL; ptr2 = ptr2->next) {
- if (ptr1->value == ptr2->value) {
- found = true;
- }
- }
- if (found == false) {
- list_node_t *new_ptr = malloc(sizeof(list_node_t));
- new_ptr->value = ptr1->value;
- new_ptr->next = NULL;
- if (new_head == NULL) {
- new_head = new_ptr;
- new_current = new_ptr;
- } else {
- new_current->next = new_ptr;
- new_current = new_current;
- }
- }
- }
- return new_head;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement