Question: Consider the following code. What is printed by the code that follows the function definitions? Pay attention to when fprintf functions are triggered. function q
Consider the following code. What is printed by the code that follows the function definitions? Pay attention to when fprintf functions are triggered. function q = enqueue (v, q) q = [v q]: fprintf('enqueing %d into queue ', v): end function [v q] = dequeue(q) v = q(end): fprintf('dequeing %d from queue ', v): q = q(1: end-1): end function s = push(v, s) s = [v s]: fprintf('pushing %d onto stack ', v): end function [v s] = pop(s) v = s(1): fprintf('popping %d from stack , v): s = (2: end): end s1 = [1]: s2 = [2 3]: q = [4 5]: [v s2] = pop(s2) q = enqueue(v, q) [v q] = dequeue(q): s2 = push(v, s2): [v s2] = pop(s2): s1 = push(v, s1) [v q] = dequeue(q): s1 = push(v, s1) [v q] =dequeue(q): s2 = push(v, s2) [v s2] = pop(s2) [v s2] = pop(s2): s1 = push(v, s1) disp(s1): disp(s2): disp(q)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
