一、java Bean
package com.hgldp.web.pojo;
import java.util.LinkedList;
/**
* @author hgl
* @data 2018年11月3日
* @description b-tree 结点
*/
public class BSTNode {
/*
* 关键字数量
*/
private int keynum;
/*
* 关键字集合
*/
private LinkedList<Integer> keys;
/*
* 孩子结点的集合
*/
private LinkedList<BSTNode> childs;
/*
* 父结点
*/
private BSTNode parent;
public int getKeynum() {
return keynum;
}
public void setKeynum(int keynum) {
this.keynum = keynum;
}
public LinkedList<Integer> getKeys() {
return keys;
}
public void setKeys(LinkedList<Integer> keys) {
this.keys = keys;
}
public LinkedList<BSTNode> getChilds() {
return childs;
}
public void setChilds(LinkedList<BSTNode> childs) {
this.childs = childs;
}
public BSTNode getParent() {
return parent;
}
public void setParent(BSTNode parent) {
this.parent = parent;
}
@Override
public String toString() {
return "BSTNode [keynum=" + keynum + ", keys=" + keys + ", childs=" + childs + ", parent=" + parent + "]";
}
}
package com.hgldp.web.pojo;
/**
* @author hgl
* @data 2018年11月3日
* @description 查找的结果
*/
public class Result {
/*
* 查找到的结点(如果未找到就是可以插入到的结点)
*/
private BSTNode ptr;
/*
* 查找到的在集合中的位置(如果未找到即为可以插入的位置)
*/
private int i;
/*
* 查找的结果的标志
* false 未找到
* true 找到
*/
private boolean tag;
public Result(BSTNode ptr, int i, boolean tag) {
this.ptr = ptr;
this.i = i;
this.tag = tag;
}
public BSTNode getPtr() {
return ptr;
}
public void setPtr(BSTNode ptr) {
this.ptr = ptr;
}
public int getI() {
return i;
}
public void setI(int i) {
this.i = i;
}
public boolean isTag() {
return tag;
}
public void setTag(boolean tag) {
this.tag = tag;
}
@Override
public String toString() {
return "Result [ptr=" + ptr + ", i=" + i + ", tag=" + tag + "]";
}
}
二、B-Tree
/**
* @author hgl
* @data 2018年11月3日
* @description b-tree 树
*/
public class BTree {
/*
* b-tree的介
*/
private int degree;
/*
* b-tree的根结点
*/
private BSTNode root;
public int getDegree() {
return degree;
}
public void setDegree(int degree) {
this.degree = degree;
}
public BSTNode getRoot() {
return root;
}
public void setRoot(BSTNode root) {
this.root = root;
}
public BTree(int degree,BSTNode root) {
this.degree = degree;
this.root = root;
}
/**
* Result
*