fixed bug

This commit is contained in:
navid.sassan 2020-10-25 21:53:32 +01:00
parent c105ea5ca7
commit 15e26130cf

View File

@ -74,17 +74,17 @@ public class TreeTraversal<T extends Comparable<T>> implements Traversal<T> {
if (node != null) { if (node != null) {
// only visit nodes that are in the interval // only visit nodes that are in the interval
if (node >= min && node <= max) { if (min.compareTo(node) <= 0 && max.compareTo(node) >= 0)
v.visit(root.element); v.visit(root.element);
} }
// go in the direction of lower values (so left) until the min is hit // go in the direction of lower values (so left) until the min is hit
if (node >= min) { if (min.compareTo(node) <= 0) {
interval(node.left, min, max, v); interval(node.left, min, max, v);
} }
// go in the direction of higher values (so right) until the max is hit // go in the direction of higher values (so right) until the max is hit
if (node <= max) { if (max.compareTo(node) >= 0) {
interval(node.right, min, max, v); interval(node.right, min, max, v);
} }
} }