Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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
image text in transcribed

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_2

Step: 3

blur-text-image_3

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

Oracle Database 10g Insider Solutions

Authors: Arun R. Kumar, John Kanagaraj, Richard Stroupe

1st Edition

0672327910, 978-0672327919

More Books

Students also viewed these Databases questions