private void AssertValid <T>(ITwoThree <T> tree) { var values = tree.GetValues().ToArray(); Assert.True(tree.IsBalanced()); CollectionAssert.IsOrdered(values); CollectionAssert.AllItemsAreUnique(values); }
public bool IsBalanced(out int depth) { int ld, rd; var lv = Left.IsBalanced(out ld); var rv = Right.IsBalanced(out rd); depth = ld + 1; return(lv && rv && ld == rd); }
public bool IsBalanced(out int depth) { int ld, md, rd; var lv = Left.IsBalanced(out ld); var mv = Middle.IsBalanced(out md); var rv = Right.IsBalanced(out rd); depth = ld + 1; return(lv && mv && rv && (ld == rd) && (ld == md)); }
public static bool IsBalanced <T>(this ITwoThree <T> node) { int depth; return(node.IsBalanced(out depth)); }