Question: i . Provide implementation of Stack class. ii . Define the constructor for SpecialStack class iii. Provide definition of push ( ) in SpecialStack that

i. Provide implementation of Stack class.
ii. Define the constructor for SpecialStack class
iii. Provide definition of push() in SpecialStack that puts a check on the value and only pushes it if its the greater than the largest value already stored on the stack.
8
class Stack {
protected:
int* array;
int size;
int top;
public:
Stack(int stackSize) : size(stackSize), top(-1){array = new int[size];
~Stack();
void push(int);
int pop();
bool isEmpty();
bool isFull();
}
};
---------------------------------------------------------------------------------------------------------------------------------------------------------
class SpecialStack : public Stack {
public:
void push(int value);
};
---------------------------------------------------------------------------------------------------------------------------------------------------------
int main(){
stack.push(3);
stack.push(7);
stack.push(1);
stack.push(5);
SpecialStack stack(5);
while (!stack.isEmpty()){ cout << "Popped: "<< stack.pop()<< endl;}
return 0;
}

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!