AuD
Lecture 'Algorithmen und Datenstrukturen' (code examples)
BTreeExample.java
Go to the documentation of this file.
1package aud.example;
2
3import aud.util.*;
4
5import aud.BTree;
6import aud.KTreeNode;
7import java.util.Scanner;
8
12public class BTreeExample extends SingleStepper {
13
14 class MyTree extends BTree<String> {
15 BTreeExample app_ = null;
16 public MyTree(int m,BTreeExample app) { super(m); }
17
18 @Override protected void onSplit(KTreeNode<String> node) {
19 // TODO decorate node
20 halt("insert requires split...");
21 super.onSplit(node);
22 }
23 }
24
25 protected MyTree tree_ = null;
26 protected DotViewer viewer_ = DotViewer.displayWindow
27 ((String) null,"aud.example.BTreeExample");
28
30 public BTreeExample(int m) {
31 super("aud.example.BTreeExample");
32 tree_=new MyTree(m,this);
33 }
34
35 public MyTree getTree() { return tree_; }
36
37 @Override protected void onHalt() {
38 if (tree_!=null)
40 }
41
43 public static void main(String[] args) {
44
45 final String HELP=
46 "usage: java aud.example.BTreeExample [M] [pause]\n"+
47 " Reads and insert words from standard input.\n"+
48 " 'quit' quits.\n"+
49 "\tpause [milliseconds] set pause between animation steps\n"+
50 "\t A value of 0 requires to explicitly push the 'continue'\n"+
51 "\t button. The default value is 0 (or the value of then\n"+
52 "\t environment variable 'AUD_TIMEOUT')!\n";
53
54 int m=args.length>0 ? Integer.parseInt(args[0]) : 1;
55
56 BTreeExample app=new BTreeExample(m);
57
58 if (args.length>1) {
59 try {
60 app.setTimeout(Integer.parseInt(args[1]));
61 } catch (NumberFormatException e) {
62 System.err.println(HELP);
63 System.exit(-1);
64 }
65 }
66
67 app.halt("EMPTY TREE");
68
69 Scanner s=new Scanner(System.in);
70 s.useDelimiter("\\s+");
71
72 while (s.hasNext()) {
73 String key=s.next();
74 if (key.compareTo("quit")==0)
75 break;
76 else {
77 app.getTree().insert(key);
78 app.halt("inserted '"+key);
79 }
80 }
81 app.halt("QUIT");
82 System.exit(0);
83 }
84}
example: insert entries
static void main(String[] args)
start interactive example
BTreeExample(int m)
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