ConvertToRPN Flashcards

1
Q

What data structure are the Precendence’s stored in, in ConvertToRPN?

A

Dictionary<string, int> Precedence = new Dictionary<string, int>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Explain :
{ “+”, 2 }, { “-“, 2 }, { “*”, 4 }, { “/”, 4 }

A
  • and / have higher precedence (4) than + and - (2).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What exactly is happening ?
int Operand = GetNumberFromUserInput(UserInput, ref Position);
List<string> UserInputInRPN = new List<string> { Operand.ToString() };
Operators.Add(UserInput[Position - 1].ToString());</string></string>

A

Reads the first number using GetNumberFromUserInput.

Initializes an Operators list for storing operators temporarily.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Explain how this function works?

A

You get a list of tokens in Reverse Polish Notation, where operator precedence is resolved by the algorithm. Example:

Expression: 2+3*4

RPN: 2 3 4 * +

How well did you know this?
1
Not at all
2
3
4
5
Perfectly