-
Mental block on this assignment
Write a program in Java that takes as input a mathematical expression consisting of decimal numbers and the four basic mathematical operators (addition, subtraction, multiplication and division) and nested mathematical expressions, and evaluates this expression.
Some examples:
• 5 + 6 * 2
• (5 + 4) * (4 - 2)
• (4 + (2 * (2 - 1))) * 1.2
Any ideas as to how I could go about this? Any general algorithms would be good. I think you have to use a composite design pattern?
Cheers
-
you need to convert the expression from infix to postfix and then use a stack to evaluate it. There are several examples on how to do this on the web.
-
 Originally Posted by celerity66
you need to convert the expression from infix to postfix and then use a stack to evaluate it. There are several examples on how to do this on the web.
Do you mean INORDER to POSTORDER or there is infix and postfix as well?
-
Right... Inorder to postorder. Here is a link: Math Expression Evaluation
Similar Threads
-
Replies: 1
Last Post: 10-05-2006, 05:07 PM
-
By software_develo in forum .NET
Replies: 3
Last Post: 08-15-2006, 11:26 AM
-
By premartha in forum C++
Replies: 3
Last Post: 10-21-2005, 10:06 AM
-
By balamemory in forum .NET
Replies: 0
Last Post: 03-05-2005, 04:16 AM
-
By Jonathan Allen in forum .NET
Replies: 331
Last Post: 03-19-2001, 08:00 AM
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