|
-
I need Help! please help me !
I am trying to do this program but I can't get it to work correctly.
For example If I put (2 * (2 + (4 + 5)))*(7 + (3)) as input I want the output to be like x * (2 + 4 + 5) * (7 + 3).
But I get 2 * (2 + (4 +5) * (7 + 3).
In other words I want the asInfix method to print the infix expression using minimum number of parentheses.
Here is the method.
public static void asInfix(BinaryTree exprTree)
{
if(!exprTree.isEmpty())
{
BinaryTree parent = exprTree;
boolean inMultOrDiv = (parent==null)?false (parent.value().equals("*")||parent.value().equals("/"))&&
(exprTree.value().equals("/") || exprTree.value().equals("*")));
boolean printParent = (inMultOrDiv && (exprTree.value().equals("+")) || exprTree.value().equals("-") &&
(parent.value().equals("-")) || parent.value().equals("+"));
if(printParent){ System.out.print("(");}
PrintTree.asInfix(exprTree.left());
System.out.print(exprTree.value() + " " );
PrintTree.asInfix(exprTree.right());
if(printParent){ System.out.print(")");}
}
}
Please help me, I am really running out of time. This is due tomorrow night. Than you, than you....
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks