#include #include "stack-ve.h" //-------------------------------------------- // Construtor //-------------------------------------------- StackVE::StackVE(int size) : Stack() { std::cout<<"\n Construindo pilha - vetor\n"; data_ = new int[size]; topIndex_ = -1; this->size_ = size; } //-------------------------------------------- // Destructor //-------------------------------------------- StackVE::~StackVE() { std::cout<<"\n Removendo pilha - vetor\n"; delete [] data_; } //-------------------------------------------- // Stack Methods //-------------------------------------------- void StackVE::push(int n) { if( isFull() ) { std::cerr<<"\nErro: nao pode fazer push em pilha cheia"; return; //exit(-1); } data_[++topIndex_] = n; } int StackVE::pop() { if( isEmpty() ) { std::cerr<<"\nErro: nao pode fazer pop em pilha vazia"; return -99999; //exit(-1); } return data_[topIndex_--]; } int StackVE::top() { if( isEmpty() ) { std::cerr<<"\nErro: nao pode fazer top em pilha vazia"; return -99999; //exit(-1); } return data_[topIndex_]; }