forked from IshitaTakeshi/Graph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bfs_test.c
56 lines (48 loc) · 1.22 KB
/
bfs_test.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "graph.h"
#include "search.h"
int main(void) {
Graph *graph;
Node *A, *B, *C, *D, *E, *F, *G, *H, *I, *J, *K;
char *path;
graph = init_graph();
A = create_node('A');
B = create_node('B');
C = create_node('C');
D = create_node('D');
E = create_node('E');
F = create_node('F');
G = create_node('G');
H = create_node('H');
I = create_node('I');
J = create_node('J');
K = create_node('K');
connect(A, C); connect(A, I);
connect(B, D); connect(B, G); connect(B, H);
connect(C, D); connect(C, G);
connect(D, H); connect(D, I); connect(D, J);
connect(E, F); connect(E, H); connect(E, J);
connect(F, G); connect(F, K);
connect(H, J);
connect(J, K);
add_node(graph, A);
add_node(graph, B);
add_node(graph, C);
add_node(graph, D);
add_node(graph, E);
add_node(graph, F);
add_node(graph, G);
add_node(graph, H);
add_node(graph, I);
add_node(graph, J);
add_node(graph, K);
printf("graph\n");
show_graph(graph, 0);
path = breath_first_search(graph, A, K);
printf("path:%s\n", path);
free(path);
free_graph(graph);
return 0;
}