java - Depth First Search - Perform DFS on a tree
Posted
by
DJDonaL3000
on Stack Overflow
See other posts from Stack Overflow
or by DJDonaL3000
Published on 2010-12-29T23:50:54Z
Indexed on
2010/12/29
23:54 UTC
Read the original article
Hit count: 180
Im trying to perform DFS on a Minimum Spanning Tree which contains 26 nodes. Nodes are named 'A' to 'Z' and the tree is undirected.
I have an empty function called DFS here that I am trying to write, which (i presume) takes in the tree (a 2D array) a startNode (randomly selected node 'M') and the endNode (randomly selected node 'Z').
The weights of connected nodes are identified in the 2D array parameter, but how do I actually get started visiting nodes?
All that is required is to print each nodeName in the order of the DFS traversal.
Do I need to create a Node_class for each node in the 2d array??
© Stack Overflow or respective owner