How would I Evaluate a certain formula?

后端 未结 4 1317
旧时难觅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:44

    A possibility is write a sort of parser. It's better to use a binary tree structure to represent an expression, rather than a list.

    Each non-leaf node is an operation and every leaf is operand.

    tree

提交回复
热议问题