Since this is not a question on the string manipulation but rather on stacks a simpler solution with StringTokenizer should be used

For both solution 1 and 2 in the problem, using the StringTokenizer would make it more concise and to the point. This would make one concentrate on the algorithm related to the problem rather than solving two problem, one of parsing of a string and another of evaluating of an expression.

Type your question above this line.


Hi Peter,

You are right. We have multiple solutions to solve this problem. Here we are not discussing all possible solutions but rather the ones where we can use stack to solve the problem.

Here we propose the generic solutions that can be used for all the languages.

StringTokenizer may be available for Java, but it might not be available for any other language. So, proposing a more general and generic solution will allow us to solve the problem in any language.

I hope I was able to help you. If you have any queries, you can ask me.

Thank you so much for your kindness.