Skip to content

Commit 42013bc

Browse files
committed
Add pre_order_dfs_vertices
1 parent 35be64d commit 42013bc

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/Graphs/abstractgraph.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,11 @@ end
261261
return post_order_dfs_vertices(dfs_tree_graph, root_vertex)
262262
end
263263

264+
@traitfn function pre_order_dfs_vertices(graph::::(!IsDirected), root_vertex)
265+
dfs_tree_graph = dfs_tree(graph, root_vertex)
266+
return pre_order_dfs_vertices(dfs_tree_graph, root_vertex)
267+
end
268+
264269
@traitfn function post_order_dfs_edges(graph::::(!IsDirected), root_vertex)
265270
dfs_tree_graph = dfs_tree(graph, root_vertex)
266271
return post_order_dfs_edges(dfs_tree_graph, root_vertex)
@@ -336,6 +341,10 @@ end
336341
return [node.vertex for node in PostOrderDFS(TreeGraph(graph, root_vertex))]
337342
end
338343

344+
@traitfn function pre_order_dfs_vertices(graph::::IsDirected, root_vertex)
345+
return [node.vertex for node in PreOrderDFS(TreeGraph(graph, root_vertex))]
346+
end
347+
339348
# Traverse the tree using a [post-order depth-first search](https://en.wikipedia.org/wiki/Tree_traversal#Depth-first_search), returning the edges where the source is the current vertex and the destination is the parent vertex.
340349
# Assumes the graph is a [rooted directed tree](https://en.wikipedia.org/wiki/Tree_(graph_theory)#Rooted_tree).
341350
# Returns a list of edges directed **towards the root vertex**!

src/NamedGraphs.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ export NamedGraph,
168168
path_digraph,
169169
path_graph,
170170
periphery,
171+
pre_order_dfs_vertices,
171172
post_order_dfs_vertices,
172173
post_order_dfs_edges,
173174
radius,

0 commit comments

Comments
 (0)