File tree Expand file tree Collapse file tree 1 file changed +8
-0
lines changed
searchingAlgo/DepthFirstSearch Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Original file line number Diff line number Diff line change
1
+ /* *
2
+ * Creates a Graph with [size] nodes
3
+ * @param init constructor for adding the edges of the nodes delegated to the instances
4
+ */
1
5
class Graph (size : Int , init : Graph .() -> Unit ) {
2
6
val adjacency: Array <MutableList <Int >> = Array (size) { ArrayList () }
3
7
@@ -6,6 +10,10 @@ class Graph(size: Int, init: Graph.() -> Unit) {
6
10
fun addEdge (node : Int , to : Int ) = adjacency[node].add(to)
7
11
}
8
12
13
+ /* *
14
+ * Prints the route taken when exploring the [graph] starting from [current]
15
+ * @param searched an array of booleans relating to whether the relating nodes have been searched
16
+ */
9
17
fun depthFirstSearch (graph : Graph , current : Int , searched : Array <Boolean > = Array (graph.adjacency.size) { false }) {
10
18
if (! searched[current]) {
11
19
searched[current] = true
You can’t perform that action at this time.
0 commit comments