Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the following code. (a) What is the final result of the code that follows the function definitions? (b) The pop function does not test

image text in transcribed
Consider the following code. (a) What is the final result of the code that follows the function definitions? (b) The pop function does not test to see if the stack is already empty. Add the code to test for this that returns 0 and the empty stack if this is the case. (c) Draw the parse tree for the expression in x. (d) Express the expression in the usual infix notation. function s = push(v, s) s = [v s]: end function [v s] = pop(s) v = s(1): s = s(2: end): end x = {5, 14, 2, '*' 6, 4, '+', '-'. 3, '+', '*'} stack = []: for ii = 1: length(x) if isnumeric(x{ii}) stack = push(x(ii), stack) elseif ismember (x(ii), '+*-/' [a stack] = pop(stack): [b stack] = pop (stack): c = eval ([sprintf (a) x(ii) sprintf(b)]): stack = push(c, stack): end end (v stack] = pop(stack): disp(v) Consider the following code. (a) What is the final result of the code that follows the function definitions? (b) The pop function does not test to see if the stack is already empty. Add the code to test for this that returns 0 and the empty stack if this is the case. (c) Draw the parse tree for the expression in x. (d) Express the expression in the usual infix notation. function s = push(v, s) s = [v s]: end function [v s] = pop(s) v = s(1): s = s(2: end): end x = {5, 14, 2, '*' 6, 4, '+', '-'. 3, '+', '*'} stack = []: for ii = 1: length(x) if isnumeric(x{ii}) stack = push(x(ii), stack) elseif ismember (x(ii), '+*-/' [a stack] = pop(stack): [b stack] = pop (stack): c = eval ([sprintf (a) x(ii) sprintf(b)]): stack = push(c, stack): end end (v stack] = pop(stack): disp(v)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Development For Dummies

Authors: Allen G. Taylor

1st Edition

978-0764507526

More Books

Students also viewed these Databases questions