Program for evaluation of postfix expression using stack in java
Active 5 years, 5 months ago. Viewed 23k times. Improve this question. TMan TMan 3, 18 18 gold badges 58 58 silver badges bronze badges. Add a comment. Active Oldest Votes. Improve this answer. Jeshen Appanna Jeshen Appanna 4 4 silver badges 16 16 bronze badges. Are you popping immediately after pushing? Dave Newton Dave Newton k 23 23 gold badges silver badges bronze badges. I got it Yeah, immediately removing the data you put somewhere is almost never good ; — Dave Newton.
As explained in the question. AnkurMarwaha What? That's already known, the issue was the logic error. Show 1 more comment. There is another logical error in this solution. The stack now looks like this:. Finally, we reach the end of the string, and the Postfix Stack will have the only value which is the result of the total evaluation:. Note: We evaluate each pair of popped operands with the operator in reverse order to avoid errors in the result.
Space Complexity: We use a Stack which will at the most store all the Operands until we get an Operator so space complexity is O T , T is the total number of operands in expression. Your email address will not be published. Save my name, email, and website in this browser for the next time I comment.
Home Contact About Advertise. Vijay Sinha Data Structure Leave a comment. Evaluate Postfix Expression in Java In this article, we will look at how to evaluate a given Postfix expression to a result value.
Note: The Postfix expression will be given as a String Input. Are you popping immediately after pushing? Dave Newton Dave Newton k 23 23 gold badges silver badges bronze badges. I got it Yeah, immediately removing the data you put somewhere is almost never good ; — Dave Newton. As explained in the question. AnkurMarwaha What? That's already known, the issue was the logic error.
Show 1 more comment. There is another logical error in this solution. Seki Noob Noob 11 1 1 bronze badge. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown.
0コメント