Question: Consider the following statements : stackType stack(50); int num; Suppose that the input is : 31 47 86 39 62 71 15 63 -99 Show

Consider the following statements :

stackType stack(50);

int num;

Suppose that the input is :

31 47 86 39 62 71 15 63 -99

Show what is output by the following segment of code:

cin >> num;
while(num != -99)
{
 if (!stack.full())
 {
 if (num % 2 == 0 || num % 3 == 0)
 stack.push(num);
 else
 if (!stack.empty())
 {
 cout << stack.top1() << " ";
 stack.pop();
 }
 else
 stack.push(num + 3);
}
cin >> num;
}
cout << endl;
cout << "Stack Elements: ";
while(!stack.empty()) 
{
 cout << " " << stack.top1(); 
 stack.pop(); 
}
cout << " ";

****************please explain as thorough as possible with as many //comments to fully teach this toa person whi has limited knowledge**********

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!