Skip to content

Commit

Permalink
修改线段树的一个 bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Xikl committed Jan 8, 2019
1 parent b22b0c7 commit 7a78fc6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public E getLast() {

/**
* 修改其中的值
*
* todo
* @param index 所因为位置
* @param element 元素
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ public class SegmentTree<E> {
public SegmentTree(E[] arr, BinaryOperator<E> merger) {
data = (E[]) Arrays.stream(arr).toArray();
tree = (E[]) new Object[4 * data.length];
buildSegmentTree(0, 0, data.length);
// 要优先赋值
this.merger = merger;
// 对于根节点 右边界应该 length - 1 如八个元素 [0, 7]
buildSegmentTree(0, 0, data.length - 1);
}

/**
Expand Down

0 comments on commit 7a78fc6

Please sign in to comment.