Interesting approach!
I've personally done something similiar in a project a few weeks ago. First, I'm taking the input in infix notation (1 + 2) and convert it into RPN (reverse polish notation, 1 2 +) using Dijkstra's Shunting-yard algorithm.
1 + 2
1 2 +
Having the expression in RPN format, you start solving it by pushing values and operators on a Stack and pop()-ing through them, until no more data to process is available.
pop()
You can see my code over here on Github inside the project I used it for: github.com/RicoBrase/ChatCalculato...
Asscociated unit test: github.com/RicoBrase/ChatCalculato...
There are some code leftovers from experimenting with Optionals, just ignore that. 😉
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Interesting approach!
I've personally done something similiar in a project a few weeks ago.
First, I'm taking the input in infix notation (
1 + 2
) and convert it into RPN (reverse polish notation,1 2 +
) using Dijkstra's Shunting-yard algorithm.Having the expression in RPN format, you start solving it by pushing values and operators on a Stack and
pop()
-ing through them, until no more data to process is available.You can see my code over here on Github inside the project I used it for:
github.com/RicoBrase/ChatCalculato...
Asscociated unit test:
github.com/RicoBrase/ChatCalculato...
There are some code leftovers from experimenting with Optionals, just ignore that. 😉