ConvertToRPN Flashcards
What data structure are the Precendence’s stored in, in ConvertToRPN?
Dictionary<string, int> Precedence = new Dictionary<string, int>
Explain :
{ “+”, 2 }, { “-“, 2 }, { “*”, 4 }, { “/”, 4 }
- and / have higher precedence (4) than + and - (2).
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>
Reads the first number using GetNumberFromUserInput.
Initializes an Operators list for storing operators temporarily.
Explain how this function works?
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 * +