3import java.util.Scanner;
20 private static void usage() {
22 "usage: java aud.example.RendererTree TREE FORMAT [M]\n"+
23 " Reads and insert words from standard input into tree, which\n"+
25 " - TREE is one of {b,avl,rb,234,B}.\n"+
26 " - FORMAT is one of {-,svg,pdf}. If FORMAT is '-' the tree is shown\n"+
27 " in a new window. Otherwise, files 'tree.dot' and 'tree.dot.FORMAT'\n"+
28 " are created instead of direct rendering.\n"+
29 " - M is the parameter of a B-tree of order 2-*m+1.\n"
32 System.err.println(HELP);
36 public static void main(String args[]) {
44 if (args[1].compareTo(
"svg")==0 ||
45 args[1].compareTo(
"pdf")==0) {
48 else if (args[1].compareTo(
"-")!=0) {
49 System.err.println(
"invalid FORMAT specifier '"+args[1]+
"'");
53 Scanner s=
new Scanner(System.in);
54 s.useDelimiter(
"(\\s|;,\\.-\"\\'\\(\\)\\[\\])+");
57 BinarySearchTree<String,String> tree=
null;
59 if (args[0].compareTo(
"b")==0) {
61 tree=
new BinarySearchTree<String,String>();
63 if (args[0].compareTo(
"avl")==0) {
65 tree=
new AVLTree<String,String>();
67 else if (args[0].compareTo(
"rb")==0) {
69 tree=
new RedBlackTree<String,String>();
74 tree.insert(s.next(),
null);
79 if (args[0].compareTo(
"234")==0) {
81 A234Tree<String> t=
new A234Tree<String>();
86 else if (args[0].compareTo(
"B")==0) {
89 System.err.println(
"missing parameter M");
92 BTree<String> t=
new BTree<String>(Integer.parseInt(args[2]));
98 System.err.println(
"invalid TREE specifier '"+args[0]+
"'");
103 System.err.println(
"Rendering output.");
107 File outfile=(
new Graphviz()).renderDotFileToFile(dotfile,format);
108 System.err.println(
"Wrote '"+dotfile+
"' and '"+outfile+
"'");
Utility for rendering various trees.
static void main(String args[])
Simple viewer for Graphvizable.
static DotViewer displayWindow(Graphvizable object, String caption)
create new DotViewer (toplevel window) and display object
void setExitOnClose()
exit application if viewer is closed
Use GraphViz to render graph structures.
System related utilities.
static File writeToFile(File file, String text)
write text to file @endiliteral
Interface for GraphViz rendering.
String toDot()
Get dot representation.
utilities (not related to AuD lecture)
AuD lecture: Data structures, algorithms, examples.