跳转至

typedef unsigned long item;
class stack{
private:
    enum {MAXN=10};
    item data[MAXN];
public:
    stack();
    bool is_empty();
    bool is_full();
    bool push(item);
    bool pop();
    item top();
    item size();
};
stack::stack(){
    data[0]=0;
}
bool stack::is_empty(){
    return data[0]==0;
}
bool stack::is_full(){
    return data[0]==MAXN-1;
}
bool stack::push(item val){
    data[++data[0]]=val;
    return this->is_full();
}
bool stack::pop(){
    if(this->is_empty()) return false;
    return data[--data[0]],true;
}
item stack::top(){
    return data[data[0]];
}
item stack::size(){
    return data[0];
}

评论