Commit 39c17309 authored by pysaumont's avatar pysaumont
Browse files

Fixes after AC review for chapter 10

parent 7ab9918d
......@@ -16,7 +16,7 @@ public class TreeTest {
@Test
public void testMin() throws Exception {
Tree<Integer> tree = Tree.tree(4, 2, 6, 1, 3, 7, 5);
assertTrue(tree.max().map(i -> i.equals(1)).getOrElse(false));
assertTrue(tree.min().map(i -> i.equals(1)).getOrElse(false));
}
@Test
......@@ -28,6 +28,6 @@ public class TreeTest {
@Test
public void testMin2() throws Exception {
Tree<Integer> tree = Tree.tree(1, 2, 3, 4, 5, 6, 7);
assertTrue(tree.max().map(i -> i.equals(1)).getOrElse(false));
assertTrue(tree.min().map(i -> i.equals(1)).getOrElse(false));
}
}
......@@ -88,7 +88,7 @@ public abstract class Tree<A extends Comparable<A>> {
public boolean member(A value) {
return value.compareTo(this.value) < 0
? left.member(value)
: value.compareTo(this.value) <= 0 || right.member(value);
: value.compareTo(this.value) == 0 || right.member(value);
}
@Override
......
......@@ -401,7 +401,7 @@ public abstract class Tree<A extends Comparable<A>> {
return balance_(tree.toListInOrderRight().foldLeft(Tree.<A>empty(), t -> a -> new T<>(empty(), a, t)));
}
public static <A extends Comparable<A>> Tree<A> balance_(Tree<A> tree) {
private static <A extends Comparable<A>> Tree<A> balance_(Tree<A> tree) {
return !tree.isEmpty() && tree.height() > log2nlz(tree.size())
? Math.abs(tree.left().height() - tree.right().height()) > 1
? balance_(balanceFirstLevel(tree))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment