# Stack Queue Hand Executions Perform Several Hand Executions Following Stack Queue Algorith Q35570591

Stack and Queue Hand Executions Perform several HAND EXECUTIONS of the following stack and queue algorithms. This is not an implementation, which means you do NOT have to write code. Instead, draw lots of nice pretty diagrams. Your diagrams should be suitable for explaining the algorithm to a non- computer scientist “regular person”. Part 0 Fully Parenthesized Infix Evaluation This algorithm uses two stacks, one for operands, and one for operators. The infix expression must be fully parenthesized for this algorithm to work. Use the following infix expressions for your hand execution while (c-readcharacter) if (c is a number) nums.push(c); if (c is an operator) ops.push(c); if (c is a right parenthesis) { num1-nums.pop) num2-nums.pop) op-ops.pop); ans-num2 op num1 nums.push(ans); if (c is a left parenthesis) do_nothing ans pop); Part 1 Infix to Postfix Conversion and Evaluation: Given an input string of characters representing an infix expression of the form “12 (34-5)”, the following algorithm fills a queue with the postfix equivalent “12 34 5 – *”. The second algorithm then evaluates the value of the expression. A “token” is either a right parenthsis, a left parenthesis, an operation symbol (+, -, *, /), or a multidigit integer The Infix Expressions: Use the following infix expressions for your hand execution 7) 2″(3+4)*5+6 Token Precedence Rules Operator/Symbol Precedence Value 2 2 0 Algorithm 1.0: Convert infix expression to postfix initialize stack and queue to empty; push(‘#’) while (not at end of expression) ( // a dummy operator having a precedence Algorithm 1.1: Evaluate postfix expressions, continuation of above initialize stack to empty; while (queue not empty) token- dequeue; if (token is an operand) push(token) operand1-pop: operand2-pop; push(result); else ( Resources There is a Visual Basic exe demo version posted you may want to use to check your answers. Requirements 1) You MUST use the algorithms provided above. 2) Perform a hand execution for each of the infix expressions given showing conversion and evaluation 3) Redraw the stack and queue often, ideally after every change, or whatever it takes to make your diagrams clear and easy to understand. Turn in: 1) Neat and professional looking paper diagrams. Documentation standards: Follow format guidelines in syllabus Show transcribed image text Stack and Queue Hand Executions Perform several HAND EXECUTIONS of the following stack and queue algorithms. This is not an implementation, which means you do NOT have to write code. Instead, draw lots of nice pretty diagrams. Your diagrams should be suitable for explaining the algorithm to a non- computer scientist “regular person”. Part 0 Fully Parenthesized Infix Evaluation This algorithm uses two stacks, one for operands, and one for operators. The infix expression must be fully parenthesized for this algorithm to work. Use the following infix expressions for your hand execution while (c-readcharacter) if (c is a number) nums.push(c); if (c is an operator) ops.push(c); if (c is a right parenthesis) { num1-nums.pop) num2-nums.pop) op-ops.pop); ans-num2 op num1 nums.push(ans); if (c is a left parenthesis) do_nothing ans pop);
Part 1 Infix to Postfix Conversion and Evaluation: Given an input string of characters representing an infix expression of the form “12 (34-5)”, the following algorithm fills a queue with the postfix equivalent “12 34 5 – *”. The second algorithm then evaluates the value of the expression. A “token” is either a right parenthsis, a left parenthesis, an operation symbol (+, -, *, /), or a multidigit integer The Infix Expressions: Use the following infix expressions for your hand execution 7) 2″(3+4)*5+6 Token Precedence Rules Operator/Symbol Precedence Value 2 2 0
Algorithm 1.0: Convert infix expression to postfix initialize stack and queue to empty; push(‘#’) while (not at end of expression) ( // a dummy operator having a precedence