Question: 1)Given a queue Q contains 1, 2, 3, 4 from front to end, and a stack S contains 10, 9, 8, 7, 6 from top

1)Given a queue Q contains 1, 2, 3, 4 from front to end, and a stack S contains 10, 9, 8, 7, 6 from top to bottom. What is the second element (from front to the end direction) in the queue after the following statements are applied?

while(!S.isEmpty())

{

if(S.top() % 2 ==0)

{

Q.enqueue(S.pop());

}

else S.pop();

}

Question 11 options:

A)

6

B)

2

C)

4

D)

8

2) What values are returned during the following series of stack operations, if executed upon an initially empty stack? push(21), push(19), pop(), push(2), push(8), pop(), pop(), push(9), push(1), pop(), push(7), push(6), pop(), pop(), push(4), pop(), pop(). (Please provide the returned values in the format "value1, value2, value3...")

3) What values are returned during the following series of queue operations, if executed upon an initially empty queue? enqueue(10), enqueue(3), dequeue(), enqueue(2), enqueue(15), dequeue(), dequeue(), enqueue(9), enqueue(1), dequeue(), enqueue(7), enqueue(6), dequeue(), dequeue(), enqueue(4), dequeue(), dequeue(). (Please provide the returned values in the format "value1, value2, value3...")

4) Provide a method with signature transfer(S, T) that transfers all elements from stack S onto stack T. After transfer, S and T will contain the same set of elements in the same order. The element that at the top of S is the element that at the top of T. (Pseudo code is good enough. You can directly use the methods defined in Queue or Stack class. Only temporary queue or stack can be used in the middle if there is a need)

5) Provide a method with signature public String InToPostFix (String s) which will accept a infix expression as a string and convert it into a post fix expression and returned the postfix expression as a string (Assume the expression only have +,-,*,/ and parentheses) . ( Check the pusduo code on the slides.)

6) Provide a method with signature public int calculation(String s) which will take a postfix expression as an input and return the calculation result of this expression. (Assume the expression only have +,-,*,/ and parentheses)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!