Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Stack{
- private:
- static const int MIN_CAPACITY=10;
- int *data;
- int stack_top=-1;
- int capacity;
- public:
- Stack();
- Stack(int capacity);
- ~Stack();
- virtual int size ();
- virtual bool isEmpty();
- virtual int top();
- virtual void push(int value);
- virtual int pop();
- virtual void print();
- };
- //Definiciones Stack
- Stack::Stack():Stack(MIN_CAPACITY){};
- Stack::Stack(int capacity):stack_top(capacity-1),capacity(capacity) {data=new int [capacity] ;};
- Stack::~Stack(){delete(data);};
- int Stack::size (){return capacity;};
- bool Stack::isEmpty(){ return (stack_top==capacity) ? true : false ;};
- int Stack::top(){return stack_top;};
- void Stack::push(int value){
- if (stack_top<0){return ;}
- *(data+stack_top)=value;
- stack_top--;
- };
- int Stack::pop(){stack_top++;return *(data+stack_top);};
- void Stack::print(){
- for (int stack=capacity-1;stack!=-1;stack--){
- cout <<stack<<" = "<<*(data+stack)<<endl;
- };
- }
- int main() {
- Stack s(3);
- cout <<"Empty "<<s.isEmpty()<<endl;
- s.push(79);
- s.push(81);
- s.push(6);
- s.push(5);
- cout <<"Size "<<s.size()<<endl;
- cout <<"Top "<<s.top()<<endl;
- //cout <<s.pop()<<endl;
- s.print();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement