How would I Evaluate a certain formula?

后端 未结 4 1313
旧时难觅i
旧时难觅i 2021-01-27 09:24

I have a multidimension arrayList and I ask the user for a formula and than I evaluate it. The problem is that I get user input like this:

  ((a1+a2)/12)*a3
         


        
4条回答
  •  一生所求
    2021-01-27 09:46

    An alternative to Heisenbug's suggestion is to try Dijkstra's shunting-yard algorithm. Instead of relying on a tree structure, you use stacks and queues. The advantage is that these data structures involved are not terribly complicated. The downside is that any errors in implementing the algorithm could be easily missed, as you need to thoroughly understand the operations involved to know if your implementation is correct.

提交回复
热议问题