0

I got this as an interview question.

What is the maximum number of elements that can be on stack at a specific moment while doing a translation from infix form to reversed postfixed Polish form?

I know that the principle is that on the stack there cannot be elements with higher priority (usually * and /) under the ones with smaller priority (+ and -). I tried making an algorithm keeping track of a global and local maximum number, but I didn`t found out a certain rule.

For example if i have infix: 2 - 3 * 4 * 5 / 1 + 10
Stack 1: - * * / => maxLocal = 4 maxGlobal = 4

Stack 2: (After eliminating /, * and * because + has lower priority) - +
=> maxLocal = 2 maxGlobal = 4

Can you please help me?

4

1 回答 1

0
于 2012-06-18T10:02:26.957 回答