-
Notifications
You must be signed in to change notification settings - Fork 0
/
union of two linklist.c
63 lines (52 loc) · 1011 Bytes
/
union of two linklist.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include"linklist.h"
// incomplete
int ispresent(Node *start,int data){
while(start!=NULL){
if(start->val==data)
return 1;
start=start->next;
}
return 0;
}
Node* unionn(Node ** list1,Node**list2){
Node* list3;
Node * curnt=list1;
Node*temp=list2;
while(curnt!=NULL){
insert_last(&list3,curnt->val);
curnt=curnt->next;
}
while(temp!=NULL){
while(curnt!=NULL)
if(temp->val==curnt->val)
curnt=curnt->next;
else{
insert_last(&list3,temp->val);
curnt=curnt->next;
}
temp=temp->next;
}
return list3;
}
int main(){
Node * l1=initialize();
Node * l2=initialize();
Node * l3=initialize();
insert_beg(l1,10);
insert_beg(l1,20);
insert_beg(l1,30);
insert_beg(l1,40);
insert_beg(l1,50);
insert_beg(l2,100);
insert_beg(l2,20);
insert_beg(l2,300);
insert_beg(l2,400);
insert_beg(l2,50);
printf("first list:");
show(l1);
printf("second list:");
show(l2);
l3=unionn(&l1,&l2);
printf("union of two list");
show(l3);
}