B - 트 리 B + 트 리 정의 와 간단 한 조작
/**
 * @Author JH
 * @CreateDate 18-5-31
 * @Description B-   
 */
class Node{
    int num;
    int []key;
    Node parent;
    Node []child;
    public Node(int m) {
        this.key = new int[m];
        this.child =new Node[m];
    }
    public Node(int num, int[] key, Node parent, Node[] child) {
        this.num = num;
        this.key = key;
        this.parent = parent;
        this.child = child;
    }
}
class Result{
    Node r;
    int i;
    int tag;
}
public class B_Tree {
    public Result B_TreeSearch(Node root,int k){
        Node p=root;
        Node q=null;
        Result r=new Result();
        int i=0;
        boolean find=false;
        while (p!=null&&!find){//    k  p   
            i=search(root,k);//  k   
            if (k==p.key[i]&&find==false){
                find=true;
            }else{//q  k       
                q=p;
                p=p.child[i];
            }
        }
        r.i=i;
        if (find){
           r.r=p;//          
           r.tag=1;
        }else{//       k          
            r.r=q;
            r.tag=0;
        }return r;
    }
    public  int search (Node root,int k){
        int i=0;//     k root           key[i]<k<key[i+1]
        for(;i<root.num&&root.key[i+1]<=k;i++);
        return i;
    }
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
【Codility Lesson3】FrogJmpA small frog wants to get to the other side of the road. The frog is currently located at position X and wants to get to...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.