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