Example #1
0
        /// <summary>
        /// Performs the entered operation with the right and left child
        /// </summary>
        /// <returns></returns>
        public int Count()
        {
            switch (data)
            {
            case '+':
            {
                return(LeftChild.Count() + RightChild.Count());
            }

            case '-':
            {
                return(LeftChild.Count() - RightChild.Count());
            }

            case '*':
            {
                return(LeftChild.Count() * RightChild.Count());
            }

            case '/':
            {
                if (RightChild.Count() == 0)
                {
                    throw new DivideByZeroException();
                }
                return(LeftChild.Count() / RightChild.Count());
            }
            }
            return(-1);
        }
Example #2
0
 public override double Count()
 => Math.Abs(RightChild.Count()) <= 1e-6 ? throw new DivideByZeroException() : LeftChild.Count() / RightChild.Count();
Example #3
0
 public override double Count()
 => LeftChild.Count() + RightChild.Count();