Transform the Expression - Java

I’ve written the program to convert infix notation to Reverse Polish Notation ( http://www.codechef.com/problems/ONP/ ) in Java. Since I’m new to learning data structures/ how this problem works, I made my own stack and queue for the program. It works perfectly fine for the test cases provided, but I get a runtime (NZEC) error when I submit it.

Could anyone give me any idea why? Are there test cases without parentheses in the correct place, or test cases with numbers instead of variables?

My solution: http://www.codechef.com/viewsolution/4294815

Hi, In order to solve this problem

No need to use ‘Queue’ data structure, Stack is enough.

You donot need to worry about priorities of operators as the infix expression is properly nested with ‘(’ and ‘)’

If you have any doubt look at the following C++ solution

http://www.codechef.com/viewsolution/4295116

If you are not familiar with C++ , I also wrote a solution in java for you :slight_smile:

http://www.codechef.com/viewsolution/4295733

Hope your problem is solved

Good luck.

2 Likes

Ah thank you! Those two points are clearer now. I wonder if maybe the queue was using too much memory and was why I got NZEC?

Updated solution for anyone interested: http://www.codechef.com/viewsolution/4299141

I don’t want to spoil your learning by showing an example or fixing your code. Instead I will give provide you wiki article on algorithm to be used. Try to implement it.