Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <malloc.h>
- typedef struct element
- {
- int info;
- struct element *link;
- } node;
- node *mk_link_list (int n)
- {
- node *p = NULL, *q = NULL, *r = NULL;
- int i; int info;
- for(i = 0; i<n; i++)
- {
- scanf ("%d", &info);
- r = (node *) malloc (sizeof (node));
- r->info = info;
- r->link = NULL;
- if (p == NULL)
- p = r;
- else
- q->link = r;
- q = r;
- }
- return (p);
- }
- node *join(node *p, node *q)
- {
- node *r,*s;
- if ((p == NULL)||(q == NULL))
- return NULL;
- if(p->info < q->info){
- s=r=p;
- p=p->link;
- } else {
- s=r=q;
- q=q->link;
- }
- while(p!=NULL && q!=NULL)
- {
- if(p->info < q->info){
- r->link=p;
- r=p;
- p=p->link;
- }
- else {
- r->link=q;
- r=q;
- q=q->link;
- }
- }
- if(p!=NULL) r->link=p;
- else r->link=q;
- return(s);
- }
- int main ()
- {
- node *p1, *p2, *r,*k,*j,*a;
- int m, n;
- scanf("%d",&m);
- p1 = mk_link_list(m);
- scanf("%d",&n);
- p2 = mk_link_list(n);
- r = join(p1, p2);
- k=r;
- j=r;
- a=r;
- while(k!=NULL)
- {
- node *z=r;
- while(j!=NULL)
- {
- if(k->info==j->info)
- {
- while(z->link=!k)
- {
- z=z->link;
- }
- if (j -> link == NULL) return;
- node *t = z -> link;
- z -> link = t -> link;
- free(t);
- }
- j=j->link;
- }
- k=k->link;
- }
- while (r->link!= NULL)
- {
- printf ("%d ", r->info);
- r=r->link;
- }
- printf ("%d", r->info);
- return (0);
- }
Add Comment
Please, Sign In to add comment