java Segment Tree.java

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java Segment Tree.java相关的知识,希望对你有一定的参考价值。

/**
 * Created by Hobbes on 7/24/17.
 */

public class SegmentTree {
    void constructTree(int[] input, int[] segmentTree, int low, int high, int pos){
        if(low == high){
            segmentTree[pos] = input[low];
            return;
        }
        int mid = (low + high) / 2;
        constructTree(input, segmentTree,low, mid, 2 * pos + 1);
        constructTree(input, segmentTree,mid, high, 2 * pos + 1);
        segmentTree[pos] = Math.min(segmentTree[2 * pos + 1], segmentTree[2*pos + 2]);
    }
    int rangeminquery(int[] segTree, int qlow, int qhigh, int high, int low, int pos){
        if(qlow <= low && qhigh >= high){ // total overlap
            return segTree[pos];
        }

        if(qlow > high || qhigh < low){ // no overlap
            return Integer.MAX_VALUE;
        }

        int mid = (low + high) / 2;
        return Math.min(rangeminquery(segTree,qlow,qhigh,low,mid, 2 *pos + 1),
                    rangeminquery(segTree, qlow, qhigh, mid, high, 2 * pos + 2));
    }
}

以上是关于java Segment Tree.java的主要内容,如果未能解决你的问题,请参考以下文章

java 100.相同的Tree.java

java 100.相同的Tree.java

java 100.相同的Tree.java

java 100.相同的Tree.java

java 100.相同的Tree.java

java 100.相同的Tree.java