Question: While lineTokens is not empty: 1 . Dequeue a token from lineTokens and get its first character. 2 . If the first character is a
While lineTokens is not empty: Dequeue a token from lineTokens and get its first character. If the first character is a letter or digit, then the token is an Operand token. Enqueue the token onto the queue postfix. If the first character is a left parenthesis, then the token is a Left Parenthesis token. Push the token onto the top of the stack ops. If the first character is a right parenthesis, then the token is a Right Parenthesis token. a Pop the operator at the top of the stack ops and enqueue the popped operator onto the queue postfix. b Repeat step a above until the top of the stack ops contains a left parenthesis. c Pop the left parenthesis at the top of the stack ops and discard it If the first character is one of the operators: or then the token is an Operator token. a If the stack ops is not empty and the operator at the top of the stack ops has a higher or equal precedence than the operator token just read, then pop the operator at the top of the stack ops and enqueue the popped operator onto the queue postfix. b Repeat step a above until the stack ops is empty or the operator at the top of the stack ops has a lower precedence than the operator token just read. c Finally, push the operator token just read onto the top of the stack ops. Note: Use the given method hasHigherOrEqualPrecedence to compare the precedence of two operators to see if the first operator has a higher precedence than the second operator.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
