Question: Q 1 ( 2 0 points ) : Stack and Queue Application 3 Assume that a program reads the following values one at a time

Q1(20 points): Stack and Queue Application
3
Assume that a program reads the following values one at a time into variable x. Value -99 is to stop the program exccution.
20,6,18,6,14,8,12,7,11,15,24,26,30,-99
Trace the following Java-like pseudocode code and write down its output as exactly it would appear on the screen.
Create stack s
Create queve Q
S. push (50):
Q. enqueue (50) :
Read first input value to x;
While (x,-99)
i.
Switch (x:4)
1
Case 0: S, push (X)
Exit Switch Statement;
Case 1: If (S.isEmpty != true)
. top ()
Printout ("Stack Element: +Y);
S. pop();
Else Printout "Sorry, stack is empty";
Exit Switch Statement;
Case 2: Q.enqueue (x) ;
Exit Switch Statement;
Case 3: If (Q.isEmpty != true)
{Y= Q.front();
Printout ("Queue Element: "+Y);
Q. dequeue () ;
}
Else Printout "Sorry, queue is empty";
Exit Switch Statement;
}//end of Switch statement
Read next input value to x;
//end of While statement
Printout ("Stack Elements are: ");
While ((S.isEmpty != true)
1Y= s.top()
Printout on newline (Y);
S.pop();
1
Printout ("Queue Elements are: ");
While ((Q.isEmpty true)
& Y= Q.front ()
Printout on newline (Y);
Q. dequeue () ;
1
 Q1(20 points): Stack and Queue Application 3 Assume that a program

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!