diff options
| author | mo khan <mo.khan@gmail.com> | 2020-09-26 17:05:39 -0600 |
|---|---|---|
| committer | mo khan <mo.khan@gmail.com> | 2020-09-26 17:05:39 -0600 |
| commit | e7fc8f9de29fbcd28b32d0ad743de9af0751340a (patch) | |
| tree | d34ac73f998c3809a4546d48efa768880ebf0a68 /src/03/graph_test.c | |
| parent | ddbdfe54c7f8f1dfb819c32aff966d8f478a92e3 (diff) | |
feat: implement backtracking algorithm to visit each edge in both directions
Diffstat (limited to 'src/03/graph_test.c')
| -rw-r--r-- | src/03/graph_test.c | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/src/03/graph_test.c b/src/03/graph_test.c index e833573..55ee588 100644 --- a/src/03/graph_test.c +++ b/src/03/graph_test.c @@ -100,33 +100,41 @@ void traverse(int vertex) { printf("->(%c)", labels[vertex]); } } + for (int edge = 0; edge < 16; ++edge) { + if (graph[vertex][edge] > 0 && graph[edge][vertex] > 0) { + graph[vertex][edge] = 0; + traverse(edge); + graph[edge][vertex] = 0; + printf("->(%c)", labels[vertex]); + } + } } -void inspect_graph() { +void graph_inspect(int n) { printf("\n"); printf("| "); - for (int i = 0; i < 16; ++i) + for (int i = 0; i < n; ++i) printf("|%c", labels[i]); printf("|\n"); - for (int i = 0; i < 16; ++i) { + for (int i = 0; i < n; ++i) { printf("|%c|", labels[i]); - for (int j = 0; j < 16; ++j) + for (int j = 0; j < n; ++j) printf("%d|", graph[i][j]); printf("\n"); } } Ensure(every_edge_is_traversed_in_both_directions_at_least_once) { + int n = 16; + traverse(0); - inspect_graph(); + graph_inspect(n); - for (int i = 0; i < 16; ++i) { - for (int j = 0; j < 16; ++j) { + for (int i = 0; i < n; ++i) + for (int j = 0; j < n; ++j) assert_that(graph[i][j], is_equal_to(0)); - } - } } TestSuite *graph_tests() { |
