From 5fd74a4d1537aad0c78a1648e4c27d018287c4d9 Mon Sep 17 00:00:00 2001 From: jf-home Date: Sat, 26 Apr 2025 19:00:20 +0800 Subject: [PATCH] =?UTF-8?q?dfs=E5=92=8Cbfs=E4=BB=A3=E7=A0=81=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E5=AE=8C=E6=AF=95=EF=BC=8C=E7=8E=B0=E5=9C=A8=E6=80=9D?= =?UTF-8?q?=E8=B7=AF=E9=9D=9E=E5=B8=B8=E6=B8=85=E6=99=B0=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/graph.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/src/graph.c b/src/graph.c index fa5723b..545f334 100644 --- a/src/graph.c +++ b/src/graph.c @@ -796,12 +796,12 @@ static struct _graph_node * graph_find_unvisited_vertex(struct _graph *self) return NULL; } -static struct _graph_node * graph_find_unvisited_target(struct _graph *self, struct _graph_node *node) +static struct _graph_node * graph_find_next_unvisited_target(struct _graph *self, struct _graph_node *node) { assert(self != NULL); if (self->empty(self)) { - return false; + return NULL; } if(node == NULL) @@ -820,7 +820,7 @@ static struct _graph_node * graph_find_unvisited_target(struct _graph *self, str } edge = edge->next; } - + return NULL; } @@ -920,13 +920,7 @@ const void *graph_iter_next(struct _iterator *iter) queue->pop(queue, &node); node->visited = true; - // 2. find unvisited target node - // target = graph_find_unvisited_target(self, node); - // if(target != NULL) - // { - // queue->push(queue, &target); - // } - + // 2. find all unvisited target node and push them to queue cur_edge = node->edgehead; while (cur_edge != NULL) { @@ -934,10 +928,6 @@ const void *graph_iter_next(struct _iterator *iter) if (target != NULL && target->visited != true) { queue->push(queue, &target); - - // self->print_obj(node->obj); - // printf(" -> "); - // self->print_obj(target->obj); } cur_edge = cur_edge->next; } @@ -970,7 +960,7 @@ const void *graph_iter_next(struct _iterator *iter) cur_node->visited = true; // 3. find unvisited target node - cur_node = graph_find_unvisited_target(self, cur_node); + cur_node = graph_find_next_unvisited_target(self, cur_node); break; } else @@ -979,7 +969,7 @@ const void *graph_iter_next(struct _iterator *iter) self->stack->pop(self->stack, &cur_node); // 5. find unvisited target node - cur_node = graph_find_unvisited_target(self, cur_node); + cur_node = graph_find_next_unvisited_target(self, cur_node); // 6. [graph special] If the graph contains isolated vertices if(cur_node == NULL)