stackType<int> stack;
queueType<int>queue;
int x;
Suppose the input is: 15 28 14 22 64 35 19 32 7 11 13 30 -999
Show what is written by the following segment of code:
stack.push(0);
queue.addQueue(0);
cin>>x;
while (x != -999)
{
switch (x % 4) {
case 0: stack.push(x); break;
case 1:
if (!stack.isEmptyStack())
{ cout<<”Stack Element=”<< stack.top()
cout<<endl;
stack.pop();}
else
cout<<”Sorry, the stack is empty.”
cout<<endl; break;
case 2: queue.addQueue(x); break;
case 3: if(queue.isEmptyQueue())
{ cout<<”Queue Element=”<< queue.front()<<endl;
queue.deleteQueue();}
else
cout<<”Sorry, the queue is empty.”<<endl; break;}}
cin>>x;
cout<<”Stack Elements=”;
while (!stack.isEmptyStack())
{
cout<<stack.top()<<” “;
stack.pop();}
cout<<endl;
cout<<”Queue Elements=”;
while (!queue.isEmptyQueue())
{
cout<<queue.front()<<” “;
queue.deleteQueue();}
cout<<endl;
[quoteCan someone explain to me about this coding? I'm confused when user input 24, 64, 22, 7, 13.
The correct output I should get is:
Output:
Queue Element=0
Queue Element=14
Queue Element=22
Sorry, the queue is empty
Sorry, the queue is empty
Stack Element=32
Stack Elements=64 28 0
Queue Elements=30][/quote]
Why would you expect that output with the input you specified? The only numbers I see the same are 22, and 64 you are not showing any of the other numbers you inputted in your output.
What output do you actually get with the input you provided?