#include <iostream>
#include <vector>
using namespace std;
//Creating a stack for integers
class Stack {
public:
Stack(int capacity) {
this->capacity = capacity;
}
void push(int data) {
if(isFull()) {
cout<<"Full Stack"<<endl;
return;
}
cout<<"Added to Stack: "<<data<<"\n";
container.push_back(data);
}
void pop() {
if(isEmpty()) {
cout<<"Empty Stack!";
return;
}
cout<<"Pop: "<<container.back()<<endl;
container.pop_back();
}
int top() {
return container[container.size()-1];
}
bool isEmpty() {
return container.empty();
}
bool isFull() {
return capacity == container.size();
}
void display() {
if(isEmpty()){
cout<<endl<<"Empty Stack. Nothing to show!"<<endl;
return;
}
for(int n:container) {
cout<<n<<"\n";
}
}
private:
vector<int> container;
int capacity;
};
int main(int argc, char const *argv[]) {
Stack stack(100);
stack.push(1);
stack.push(2);
stack.push(3);
stack.push(4);
stack.pop();
stack.pop();
stack.pop();
stack.pop();
stack.pop();
stack.display();
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCi8vQ3JlYXRpbmcgYSBzdGFjayBmb3IgaW50ZWdlcnMKY2xhc3MgU3RhY2sgewoKICAgcHVibGljOgogICAgIFN0YWNrKGludCBjYXBhY2l0eSkgewogICAgICAgICAgdGhpcy0+Y2FwYWNpdHkgPSBjYXBhY2l0eTsKICAgICB9CiAgICAgdm9pZCBwdXNoKGludCBkYXRhKSB7CiAgICAgICAgICBpZihpc0Z1bGwoKSkgewogICAgICAgICAgICBjb3V0PDwiRnVsbCBTdGFjayI8PGVuZGw7CiAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgIH0KICAgICAgICAgIGNvdXQ8PCJBZGRlZCB0byBTdGFjazogIjw8ZGF0YTw8IlxuIjsKICAgICAgICAgIGNvbnRhaW5lci5wdXNoX2JhY2soZGF0YSk7CiAgICAgfQoKICAgICB2b2lkIHBvcCgpIHsKICAgICAgICAgIGlmKGlzRW1wdHkoKSkgewogICAgICAgICAgICBjb3V0PDwiRW1wdHkgU3RhY2shIjsKICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgfQogICAgICAgICAgY291dDw8IlBvcDogIjw8Y29udGFpbmVyLmJhY2soKTw8ZW5kbDsKICAgICAgICAgIGNvbnRhaW5lci5wb3BfYmFjaygpOwogICAgIH0KCiAgICAgaW50IHRvcCgpIHsKICAgICAgICAgcmV0dXJuIGNvbnRhaW5lcltjb250YWluZXIuc2l6ZSgpLTFdOwogICAgIH0KCiAgICAgYm9vbCBpc0VtcHR5KCkgewogICAgICAgICAgcmV0dXJuIGNvbnRhaW5lci5lbXB0eSgpOwogICAgIH0KCiAgICAgYm9vbCBpc0Z1bGwoKSB7CiAgICAgICAgICByZXR1cm4gY2FwYWNpdHkgPT0gY29udGFpbmVyLnNpemUoKTsKICAgICB9CgogICAgIHZvaWQgZGlzcGxheSgpIHsKICAgICAgIGlmKGlzRW1wdHkoKSl7CiAgICAgICAgIGNvdXQ8PGVuZGw8PCJFbXB0eSBTdGFjay4gTm90aGluZyB0byBzaG93ISI8PGVuZGw7CiAgICAgICAgIHJldHVybjsKICAgICAgIH0KICAgICAgIGZvcihpbnQgbjpjb250YWluZXIpIHsKICAgICAgICAgY291dDw8bjw8IlxuIjsKICAgICAgIH0KICAgICB9CiAgIHByaXZhdGU6CiAgICAgdmVjdG9yPGludD4gY29udGFpbmVyOwogICAgIGludCBjYXBhY2l0eTsKfTsKCmludCBtYWluKGludCBhcmdjLCBjaGFyIGNvbnN0ICphcmd2W10pIHsKICBTdGFjayBzdGFjaygxMDApOwogIHN0YWNrLnB1c2goMSk7CiAgc3RhY2sucHVzaCgyKTsKICBzdGFjay5wdXNoKDMpOwogIHN0YWNrLnB1c2goNCk7CiAgc3RhY2sucG9wKCk7CiAgc3RhY2sucG9wKCk7CiAgc3RhY2sucG9wKCk7CiAgc3RhY2sucG9wKCk7CiAgc3RhY2sucG9wKCk7CiAgc3RhY2suZGlzcGxheSgpOwogIHJldHVybiAwOwp9