AuD
Lecture 'Algorithmen und Datenstrukturen' (code examples)
A234TreeExample.java
Go to the documentation of this file.
1package aud.example;
2
3import aud.util.*;
4
5import aud.A234Tree;
6import aud.KTreeNode;
7import java.util.Scanner;
8
12public class A234TreeExample extends SingleStepper {
13
14 class MyA234Tree extends A234Tree<String> {
15 A234TreeExample app_ = null;
16 public MyA234Tree(A234TreeExample app,boolean bottom_up) {
17 super(!bottom_up);
18 System.err.println(bottom_up ? "bottom-up mode\n" : "top-down mode\n");
19 }
20
21 @Override protected void onSplit(KTreeNode<String> node) {
22 // TODO decorate node
23 halt("insert requires split...");
24 super.onSplit(node);
25 }
26 }
27
28 protected MyA234Tree tree_ = null;
29 protected DotViewer viewer_ = DotViewer.displayWindow
30 ((String) null,"aud.example.A234TreeExample");
31
33 public A234TreeExample(boolean bottom_up) {
34 super("aud.example.A234TreeExample");
35 tree_=new MyA234Tree(this,bottom_up);
36 }
37
38 public MyA234Tree getTree() { return tree_; }
39
40 @Override protected void onHalt() {
41 if (tree_!=null)
43 }
44
46 public static void main(String[] args) {
47
48 final String HELP=
49 "usage: java aud.example.A234TreeExample [pause] [bottom-up]\n"+
50 " Reads and insert words from standard input.\n"+
51 " 'quit' quits.\n"+
52 "\tpause [milliseconds] set pause between animation steps\n"+
53 "\t A value of 0 requires to explicitly push the 'continue'\n"+
54 "\t button. The default value is 0 (or the value of then\n"+
55 "\t environment variable 'AUD_TIMEOUT')!\n"+
56 "\tbottom-up select bottom-up splitting on insertion\n"
57 ;
58
59 A234TreeExample app=new A234TreeExample(args.length>1);
60
61 if (args.length>0) {
62 try {
63 app.setTimeout(Integer.parseInt(args[0]));
64 } catch (NumberFormatException e) {
65 System.err.println(HELP);
66 System.exit(-1);
67 }
68 }
69
70 app.halt("EMPTY TREE");
71
72 Scanner s=new Scanner(System.in);
73 s.useDelimiter("\\s+");
74
75 while (s.hasNext()) {
76 String key=s.next();
77 if (key.compareTo("quit")==0)
78 break;
79 else {
80 app.getTree().insert(key);
81 app.halt("inserted '"+key);
82 }
83 }
84 app.halt("QUIT");
85 System.exit(0);
86 }
87}
example: insert entries
static void main(String[] args)
start interactive example
A234TreeExample(boolean bottom_up)
create application instance
Simple viewer for Graphvizable.
Definition: DotViewer.java:48
void display(String code)
display dot code
Definition: DotViewer.java:108
Simple framework for single stepping code.
void halt()
wait for user
void setTimeout(int timeout)
Set global timeout.
void halt(String text, int timeout)
display text and wait for user or timeout
utilities (not related to AuD lecture)
Definition: Colormap.java:1
AuD lecture: Data structures, algorithms, examples.
Definition: A234Tree.java:1