Last active
October 24, 2018 22:16
-
-
Save jp26jp/0c33b58bb142b426eec2119497ba2fd0 to your computer and use it in GitHub Desktop.
Generates a string containing all of the edges in the tree rooted at "this" node, in DOT format.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Generates a string containing all of the edges in the tree rooted at "this" node, in DOT format. | |
* Assumes this node has member variables called “data”, “leftChild”, and “rightChild”. | |
* | |
* @return DOT format string to enter at http://www.webgraphviz.com | |
*/ | |
public String generateDot() throws Exception | |
{ | |
// `root` represents the root node of the binary search tree | |
if (root == null) | |
throw new Exception("BST not large enough to visualize."); | |
String result = "digraph BST {\n"; | |
result += " node [shape=record]\n"; | |
result += root.generateDot(); | |
return result + "}"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment