AuD
Lecture 'Algorithmen und Datenstrukturen' (code examples)
aud.example.BinarySearchTreeExample Class Reference

example: insert, remove, and restructure entries More...

+ Inheritance diagram for aud.example.BinarySearchTreeExample:
+ Collaboration diagram for aud.example.BinarySearchTreeExample:

Public Member Functions

 BinarySearchTreeExample (BinarySearchTree< String, String > tree)
 create application instance More...
 
- Public Member Functions inherited from aud.util.SingleStepper
 SingleStepper (JFrame parent)
 create new instance More...
 
 SingleStepper (String caption)
 create new instance More...
 
JFrame parent ()
 get parent widget More...
 
void halt (String text, int timeout)
 display text and wait for user or timeout
More...
 
void setTimeout (int timeout)
 Set global timeout. More...
 
SingleStepper whereAmI ()
 print location of calling code More...
 
SingleStepper showSource ()
 jmp to caller's location in editor (emacs only) More...
 
void halt (String text)
 display text and wait for user (or global timeout) More...
 
void halt ()
 wait for user More...
 

Static Public Member Functions

static void main (String[] args)
 Start interactive example. More...
 
static void main (String[] args)
 

Protected Member Functions

void onHalt ()
 
- Protected Member Functions inherited from aud.util.SingleStepper
JComponent createComponents ()
 
void onNext ()
 call on button pressed More...
 
void println (String text)
 print to both, text area and stdout More...
 
void onHalt ()
 

Protected Attributes

BinarySearchTree< String, String > tree_ = null
 
DotViewer viewer_
 
BinarySearchTree< String, String >.Decorator decorator_
 
- Protected Attributes inherited from aud.util.SingleStepper
JFrame frame
 
JTextArea history
 
JButton next
 
Object monitor = new Object()
 
int timeout = 0
 

Detailed Description

example: insert, remove, and restructure entries

See also
BinarySearchTree

Definition at line 10 of file BinarySearchTreeExample.java.

Constructor & Destructor Documentation

◆ BinarySearchTreeExample()

aud.example.BinarySearchTreeExample.BinarySearchTreeExample ( BinarySearchTree< String, String >  tree)

create application instance

Definition at line 19 of file BinarySearchTreeExample.java.

19 {
20 super("aud.example.BinarySearchTreeExample");
21 tree_=tree;
22 decorator_=(BinarySearchTree.Decorator)
23 //(BinarySearchTree<String,String>.Decorator) // compile fails on some platforms!?
24 tree_.getDecorator(); // same per tree
25 }
BinarySearchTree< String, String >.Decorator decorator_
BinarySearchTree< String, String > tree_

References aud.example.BinarySearchTreeExample.decorator_, and aud.example.BinarySearchTreeExample.tree_.

Member Function Documentation

◆ main()

static void aud.example.BinarySearchTreeExample.main ( String[]  args)
static

Start interactive example.

Type '?' for help.

Reimplemented from aud.util.SingleStepper.

Definition at line 35 of file BinarySearchTreeExample.java.

35 {
36
37 final String HELP=
38 "usage: java aud.example.BinarySearchTreeExample\n"+
39 " Reads and insert words from standard input.\n"+
40 "\tWords may be prefixed with a single character, e.g., '-x':\n"+
41 "\t- '-' remove from the tree.\n"+
42 "\t- '/' apply right rotation to left-left case with key as root\n"+
43 "\t- '\\' apply left rotation to right-right case with key as root\n"+
44 "\t- '<' apply double rotation to right-left case with key as root\n"+
45 "\t- '>' apply double rotation to left-right case with key as root\n"+
46 "\t- '=' apply tri-node restructuring with key as grandchild\n"+
47 "\t- '!' highlights a node (or none if not found)\n"+
48 "\t- '~' pauses execution\n"+
49 "\t- '?' prints this message\n"+
50 "\t- 'quit' quits.\n"+
51 "\tDuring the whole process, the tree will be visualized.";
52
53 if (args.length>0) {
54 System.err.println(HELP);
55 System.exit(-1);
56 }
57
58 BinarySearchTree<String,String> tree=
59 new BinarySearchTree<String,String>();
61
62 app.halt("EMPTY TREE",1);
63
64 Scanner s=new Scanner(System.in);
65 s.useDelimiter("\\s+");
66
67 while (s.hasNext()) {
68 String key=s.next();
69 if (key.compareTo("quit")==0)
70 break;
71 else if (key.startsWith("?")) {
72 System.err.println(HELP);
73 }
74 else if (key.startsWith("!")) {
75 key=key.substring(1);
76 app.decorator_.highlight(key);
77 app.halt("highlight '"+key+"'",10);
78 }
79 else if (key.startsWith("-")) {
80 key=key.substring(1);
81 tree.remove(key);
82 app.halt("remove '"+key+"'",200);
83 }
84 else if (key.startsWith("~")) {
85 app.halt("PAUSE '"+key.substring(1)+"'",0);
86 }
87 else if (key.startsWith("<") || key.startsWith(">") ||
88 key.startsWith("/") || key.startsWith("\\") ||
89 key.startsWith("=")) {
90 try {
91 tree.restructure(key.charAt(0),key.substring(1));
92 app.halt("restructure '"+key.substring(0,1)+
93 "' near '"+key.substring(1)+"'",200);
94 //System.out.println(tree.toText());
95 } catch (RuntimeException e) {
96 System.err.println(e);
97 app.halt(e.getMessage(),1);
98 }
99 tree.checkConsistency();
100 }
101 else {
102 tree.insert(key,null);
103 app.halt("insert '"+key+"'",200);
104 }
105 }
106 app.halt("QUIT",200);
107 System.exit(0);
108 }
BinarySearchTreeExample(BinarySearchTree< String, String > tree)
create application instance

References aud.example.BinarySearchTreeExample.decorator_, aud.util.SingleStepper.halt(), and aud.BinarySearchTree.Decorator.highlight().

+ Here is the call graph for this function:

◆ onHalt()

void aud.example.BinarySearchTreeExample.onHalt ( )
protected

Reimplemented from aud.util.SingleStepper.

Definition at line 27 of file BinarySearchTreeExample.java.

27 {
28 if (tree_!=null)
30 }
void display(String code)
display dot code
Definition: DotViewer.java:108

References aud.util.DotViewer.display(), aud.example.BinarySearchTreeExample.tree_, and aud.example.BinarySearchTreeExample.viewer_.

+ Here is the call graph for this function:

Member Data Documentation

◆ decorator_

BinarySearchTree<String,String>.Decorator aud.example.BinarySearchTreeExample.decorator_
protected

◆ tree_

BinarySearchTree<String,String> aud.example.BinarySearchTreeExample.tree_ = null
protected

◆ viewer_

DotViewer aud.example.BinarySearchTreeExample.viewer_
protected
Initial value:
= DotViewer.displayWindow
((String) null,"aud.example.BinarySearchTreeExample")

Definition at line 13 of file BinarySearchTreeExample.java.

Referenced by aud.example.BinarySearchTreeExample.onHalt().


The documentation for this class was generated from the following file: