Recursion for mathematical expressions

  • 14
  • Locked
The input is a mathematical expression in the form of a String. The expression may include whole numbers, fractional numbers, parentheses (), spaces, negative signs -, exponents ^, sin(x), cos(x), and tan(x).
You can't complete this task, because you're not signed in.
Comments (2)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Justin Smith
Level 38 , Greenfield, USA, United States
29 October 2022, 12:40
This can be done, but I feel like this is an exercise in doing something the wrong way. The recursive function would be better off written as returning a double so that you can pass substring components of the expression string and return their outcomes. Doing it as a void method is much more cumbersome, as evidenced by the official solution being over 300 lines long.
WIDMO
Level 41 , Gdańsk, Poland
29 October 2020, 17:32
Can anybody help?