Computer Science Canada recursive function problem |
Author: | efus [ Sun Nov 30, 2008 3:44 pm ] | ||
Post subject: | recursive function problem | ||
Hi, I am having some troubles with a recursive function. The function needs to get a string as an input. The string contains both symbols and numbers. What the function does is doing some operation on the two children of a node, the node being the operation(+,-,*,/). The thing is, I need the function to return a double. This couses a problem since I cant just convert the string to a double becouse of the operators. This is the algoritm:
|
Author: | Tony [ Sun Nov 30, 2008 3:52 pm ] |
Post subject: | RE:recursive function problem |
typecast the value to Double. Then you are always doing operations on two Double's, so you can just return the same type. It doesn't make sense to convert a String, since "+" in Double is meaningless. |
Author: | Vermette [ Sun Nov 30, 2008 6:18 pm ] |
Post subject: | RE:recursive function problem |
In case you're not sure what Tony is referring to: http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Double.html Make note of the valueOf(String s) method. |