Exemple #1
0
        public static bool Order(BinTree.BinNode <Range> tree)
        {
            if (tree == null)
            {
                return(true);
            }
            // if (tree == null || IsLeaf(tree)) return true; // לא חובה לבדוק האם זה עלה
            Range current = tree.GetValue();
            int   min = current.GetLow(), max = current.GetHigh();
            Range left  = tree.HasLeft() ? tree.GetLeft().GetValue() : null;
            Range right = tree.HasRight() ? tree.GetRight().GetValue() : null;

            if (left != null && (left.GetLow() != min || left.GetHigh() > max))
            {
                return(false);
            }
            if (right != null && (right.GetHigh() != max || right.GetLow() < min))
            {
                return(false);
            }
            if (left != null && right != null && left.GetHigh() >= right.GetLow())
            {
                return(false);
            }
            return(Order(tree.GetLeft()) && Order(tree.GetRight()));
        }
Exemple #2
0
 public static bool IsLeaf(BinTree.BinNode <Range> tree)
 {
     return(!tree.HasLeft() && !tree.HasRight());
 }