-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathaddition1demo.c
79 lines (73 loc) · 1.49 KB
/
addition1demo.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
struct node
{
int data;
struct node *next;
} *first1 = NULL, *first2 = NULL;
void create1(int a[], int n)
{
struct node *p, *last;
first1 = (struct node *)malloc(sizeof(struct node));
first1->data = a[0];
first1->next = NULL;
last = first1;
for (int i = 1; i < n; i++)
{
p = (struct node *)malloc(sizeof(struct node));
p->data = a[i];
p->next = NULL;
last->next = p;
last = p;
}
}
void create2(int a[], int n)
{
struct node *p, *last;
first2 = (struct node *)malloc(sizeof(struct node));
first2->data = a[0];
first2->next = NULL;
last = first2;
for (int i = 1; i < n; i++)
{
p = (struct node *)malloc(sizeof(struct node));
p->data = a[i];
p->next = NULL;
last->next = p;
last = p;
}
}
void find(struct node *p, struct node *q)
{
int pc=1,qc=1,flag=0;
//flag->denote if intersection isfound or not
//pc , qc->count off nodes of the two linked loist.
while(p->next!=NULL)
{
while(q->next!=NULL)
{
if(p->next==q->next)
{
flag=1;
break;
}
q=q->next;
qc++;
}
if(flag==1)
{
break;
}
p=p->next;
pc++;
}
}
int main()
{
int a[] = {1, 3, 5};
int b[] = {2, 4, 6};
create1(a, 3);
create2(b, 3);
return 0;
}