C++ #include <iostream> using namespace std; const int MAXSIZE = 20; class Stack
ID: 3738807 • Letter: C
Question
C++
#include <iostream>
using namespace std;
const int MAXSIZE = 20;
class Stack {
public:
Stack();
bool Empty();
void Push(int item);
void Pop();
int Top();
void displayStack();
private:
int stk[MAXSIZE];
int top;
};
Stack::Stack() {
top = 0;
}
bool Stack::Empty() {
if (top == 0)
return true;
else
return false;
}
void Stack::Push(int item) {
stk[top] = item;
top++;
}
void Stack::Pop() {
top--;
}
int Stack::Top() {
return stk[top];
}
void Stack::displayStack() {
for (int i = 0; i < top; i++)
cout << stk[i] << " ";
cout << endl << endl << top << endl;
}
Explanation / Answer
Exercise 1:
Explanation :
1) There are Two Stacks A AND B
2) for loop runs from 61 to 70
3) A stack contains numbers divisible by 3
A Stack contains 69, 66, 63
B Stack contains 70, 68, 67, 65, 64, 62, 61
PRINTING The Output we get :
Output : 70 68 67 65 64 62 61
As stack follows LIFO
Thanks, let me know if there is any concern. PLEASE RATE
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.