Skip to content

Instantly share code, notes, and snippets.

@jp26jp
Last active October 24, 2018 22:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jp26jp/0c33b58bb142b426eec2119497ba2fd0 to your computer and use it in GitHub Desktop.
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.
/**
* 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