-
Notifications
You must be signed in to change notification settings - Fork 0
/
anapt.c
103 lines (73 loc) · 1.77 KB
/
anapt.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
int reachNode1(ptr_graph graph,int id_first,int id_last,hash_f hash)
{
ptr_entry first;
ptr_entry last;
int count = 0;
int flag = 1;
ptr_edge last_edge = malloc(sizeof(struct edge));
ptr_edge prev_last_edge = malloc(sizeof(struct edge));
first = lookupNode(graph,id_first,hash);
last = lookupNode(graph,id_last,hash);
if(first != NULL && last != NULL)
{
if(first->id == last->id) return 0;
else
{
count++;
rec_bfs(graph,id_first,first,last,hash,&count,&flag,last_edge,prev_last_edge);
}
}
}
int rec_bfs(ptr_graph graph,int riza,ptr_entry current,ptr_entry last,hash_f hash,int *count,int* flag,ptr_edge last_edge,ptr_edge prev_last_edge)
{
int err;
int i;
ptr_edge *data_array;
list_ptr lista_filon;
int size;
lista_filon = (list_ptr)current->friends;
size = lista_filon->size;
data_array = LL_export(lista_filon);
err = rec_sl(current->friends,last->id,count,hash,last_edge);
if(err == 0 && *flag == 1)
{
*flag = 0;
for(i=0;i<(size-1);i++)
{
current = lookupNode(graph,data_array[i]->id,hash);
rec_bfs(graph,riza,current,last,hash,count,flag);
}
if(prev_last_edge->id == data_array[size-1]->id)
{
prev_last_edge = last_edge;
*flag = 1;
for(i=0;i<(size-1);i++)
{
current = lookupNode(graph,data_array[i]->id,hash);
rec_bfs(graph,riza,current,last,hash,count,flag);
}
}
}
else if(err == 0 && *flag == 0)
{
}
}
int rec_sl(list_ptr lista_filon,int id_last,int* counter,hash_f hash,ptr_edge last)
{
int err;
int i;
ptr_edge *data_array;
int size = lista_filon->size;
memcpy(last,data_array[size-1],sizeof(struct edge));
data_array = LL_export(lista_filon);
for(i=0;i<(size-1);i++)
{
if(data_array[i]->id == id_last)
{
free(data_array);
return 1;
}
}
free(data_array);
return 0;
}