public void Tree_Test() { var initialEquation = "3+2*4/5"; var checkPostfix = ShuntingYardAlgorithm.PostfixString(initialEquation); checkPostfix.Should().Be("324*5/+"); var arithmeticTree = ExpressionTree.BuildArithmeticTree(checkPostfix); arithmeticTree.Data.Should().Be('+'); }
private static void Main() { const string infix = "3+2*4/5"; Console.WriteLine($"Initial infix: {infix}"); // 324*5/+ var postfix = ShuntingYardAlgorithm.PostfixString(infix); Console.WriteLine($"Postfix by Shunting-yard: {postfix}"); var arithmeticTree = ExpressionTree.BuildArithmeticTree(postfix); Console.WriteLine("Infix by In-Order traversal: "); DisplayTree.InOrderTraversal(arithmeticTree); Console.WriteLine(); Console.WriteLine("Postfix notation by Post-Order traversal: "); DisplayTree.PostOrderTraversal(arithmeticTree); Console.WriteLine(); Console.WriteLine("Prefix notation by Pre-Order traversal: "); DisplayTree.PreOrderTraversal(arithmeticTree); Console.WriteLine(); Console.WriteLine("Infix: "); ExpressionTree.PrintInfixExpression(arithmeticTree); }