Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- typedef struct _node {
- char data[64];
- struct _node *next;
- } node;
- addNode(node **head, char s[64])
- {
- node * el = *head;
- node * n = (node*) malloc(sizeof(node));
- n->next = NULL;
- strcpy(n->data, s);
- if (!*head)
- {
- *head = n; return;
- }
- while (el->next)
- el = el->next;
- el->next = n;
- }
- node *finder(node *head1, node* head2)
- {
- node *l1, *l2, *rhead = NULL;
- l1 = head1;
- while (l1)
- {
- int c=0;
- l2 = head2;
- while (l2)
- {
- if (!strcmp(l1->data, l2->data)) c++;
- l2 = l2->next;
- }
- if (!c) addNode(&rhead, l1->data);
- l1 = l1->next;
- }
- return rhead;
- }
- reprint(node *head)
- {
- if (!head) return;
- reprint(head->next);
- printf("%s ", head->data);
- }
- int main()
- {
- int n, i, fi;
- char s[64];
- node *head1 = NULL, *head2 = NULL, *rhead = NULL, *f = NULL;
- printf("input L1: ");
- while (strcmp(gets(s), ""))
- addNode(&head1, s);
- printf("input L2: ");
- while (strcmp(gets(s), ""))
- addNode(&head2, s);
- rhead = finder(head1, head2);
- reprint(rhead);
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment