Example #1
0
        /// <summary>
        /// This function convert the infix notation into a binary expression tree
        /// </summary>
        /// <param name="infix"></param>
        /// <returns>binary expression </returns>
        public string ConvertExpressionTree(string infix)
        {
            NodeTree expressionTree = BiuldExpressionTree(infix);

            PrintExpressionTree(expressionTree);
            return(expressionResult.ToString());
        }
Example #2
0
        /// <summary>
        /// This function use to create Node
        /// </summary>
        /// <param name="c"></param>
        /// <returns></returns>
        private NodeTree CreateNewNode(string c)
        {
            NodeTree tree = new NodeTree();

            tree.data = c;
            tree.left = tree.right = null;
            return(tree);
        }
Example #3
0
 /// <summary>
 /// This function Print and assign expression tree into StringBuilder.
 /// </summary>
 /// <param name="tree"></param>
 private void PrintExpressionTree(NodeTree tree)
 {
     if (tree != null)
     {
         PrintExpressionTree(tree.left);
         PrintExpressionTree(tree.right);
         Console.WriteLine(tree.data);
         expressionResult.Append(tree.data);
     }
 }