Question: Answer the following questions. You do not have to write programs for this portion of the assignment. 1. What do the initially empty stacks s1
Answer the following questions. You do not have to write programs for this portion of the assignment. 1. What do the initially empty stacks s1 and s2 contain after the following sequence of operations?
s1.push(2)
s1.push(4)
s2.push(6)
s2.push(8)
a = s1.pop()
b = s2.pop()
s1.push(b)
s1.push(a)
c = s2.pop()
d = s1.pop()
s2.push(d)
s2.push(c)
2. What do the initially empty queues q1 and q2 contain after the following sequence of operations?
q1.enqueue(2)
q1.enqueue(4)
q2.enqueue(6)
q2.enqueue(8)
a = q1.dequeue()
b = q2.dequeue()
q1.enqueue(b)
q1.enqueue(a)
c = q2.dequeue()
d = q1.dequeue()
q2.enqueue(d)
q2.enqueue(c)
3. Use the stack algorithms presented in class to evaluate the following postfix expression.
wxy+z*a-*
Assume the following values for the identifiers: w=3, x=7, y=8, z=10, a=120. Show the contents of the stack after processing each character.
4. Use the stack algorithms presented in class to convert the following infix expression to postfix form. Show the contents of the stack after each step. a*(b+c)/((x-y)*z)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
