示例#1
0
        // Рекурсивное построение поддерева заданной глубины(или высоты)
        public static BinaryTree <BrocotFraction> GetSubTree(int depth)
        {
            if (depth <= 0)
            {
                return(null);
            }
            else
            {
                Fraction t     = new Fraction(1, 1);
                Fraction left  = new Fraction(0, 1);
                Fraction right = new Fraction(1, 0);

                BrocotFraction FirstStage     = new BrocotFraction(t, left, right);
                BinaryTree <BrocotFraction> b = new BinaryTree <BrocotFraction>(FirstStage);
                if (depth == 1)
                {
                    return(b);
                }
                b.value = FirstStage;
                b.right = GetSubTree(new BrocotFraction(Fraction.Mediant(b.value.current, b.value.right), b.value.current, b.value.right), depth - 1);
                b.left  = GetSubTree(new BrocotFraction(Fraction.Mediant(b.value.current, b.value.left), b.value.left, b.value.current), depth - 1);

                return(b);
            }
        }
示例#2
0
        // Рекурсивное построение поддерева заданной глубины(или высоты), вызвается в методе GetSubThree(int depth)
        public static BinaryTree <BrocotFraction> GetSubTree(BrocotFraction f, int depth)
        {
            if (depth > 0)
            {
                Fraction x = Fraction.Mediant(f.left, f.current);
                Fraction y = Fraction.Mediant(f.right, f.current);

                BrocotFraction leftSub  = new BrocotFraction(x, f.left, f.current);
                BrocotFraction rightSub = new BrocotFraction(y, f.current, f.right);

                BinaryTree <BrocotFraction> leftSubTree  = GetSubTree(leftSub, depth - 1);
                BinaryTree <BrocotFraction> rightSubTree = GetSubTree(rightSub, depth - 1);
                BinaryTree <BrocotFraction> tree         = new BinaryTree <BrocotFraction>(f, leftSubTree, rightSubTree);

                return(tree);
            }
            else
            {
                return(null);
            }
        }