9public class BTree<Key
extends Comparable<Key>> implements
Graphvizable {
16 root_=
new KTreeNode<Key>();
22 public KTreeNode<Key> root() {
return root_; }
25 public int getOrder() {
return 2*m_+1; }
31 public Key find(Key key) {
32 return root_.find(key);
38 public boolean insert(Key key) {
39 return insert(root_,key);
52 protected void split(KTreeNode<Key> node) {
53 if (node.getK()>2*m_+1) {
59 if (node.parent_!=
null) {
60 int i=node.parent_.getIndexOfChild(node);
62 node.parent_.mergeChild(i);
63 node.parent_.checkConsistency();
71 protected void onSplit(KTreeNode<Key> node) {
75 protected boolean insert(KTreeNode<Key> node, Key key) {
77 for (
int i=1; i<node.getK(); ++i) {
78 int cmp=node.compareKeys(key,node.getKey(i));
82 if (node.getChild(i-1)==
null) {
89 return insert(node.getChild(i-1),key);
93 KTreeNode<Key> right=node.getChild(node.getK()-1);
95 return insert(right,key);
97 node.insert(key,node.getK()-1);
104 public String toDot() {
105 return root_.toDot();
110 public String toTikZ() {
111 return root_.toTikZ();
114 @Override
public String toString() {
115 return root_.toString();
121 public void checkConsistency() {
123 root_.checkConsistency();
127 public static void main(String[] args) {
128 BTree<Integer> tree=
new BTree<Integer>(1);
130 int data[]={1,5,2,6,7,4,8,3};
134 System.out.println(tree.toTikZ()+
"\n");
Simple viewer for Graphvizable.
static DotViewer displayWindow(Graphvizable object, String caption)
create new DotViewer (toplevel window) and display object
Interface for GraphViz rendering.
utilities (not related to AuD lecture)
AuD lecture: Data structures, algorithms, examples.