0 Replies - 72 Views - Last Post: 19 August 2007 - 04:49 PM

#1 Xing   User is offline

  • D.I.C Addict
  • member icon

Reputation: 19
  • View blog
  • Posts: 725
  • Joined: 22-July 06

Stack class

Posted 19 August 2007 - 04:49 PM

Description:
class Stack
{
public:
    Stack()             throw();
    void push(int elem) throw();
    int  pop()          throw();
    int  top()   const  throw();
    bool full()  const  throw();
    bool empty() const  throw();
protected:
    enum
    {
        dataMax_ = 10
    };
    unsigned  len_;
    int       data_[dataMax_];
};
inline      Stack::Stack()        throw() : len_(0)
{ }
inline void Stack::push(int elem) throw()
{
    data_[len_++] = elem;
}
inline int  Stack::pop()          throw()
{
    return data_[--len_];
}
inline int  Stack::top()   const  throw()
{
    return data_[len_-1];
}
inline bool Stack::full()  const  throw()
{
    return len_ == dataMax_;
}
inline bool Stack::empty() const  throw()
{
    return len_ == 0;
}
int main()
{
    Stack s;
    s.push(0);
    s.push(1);
    s.push(2);
    s.push(3);
    s.push(4);
    s.push(5);
    s.push(6);
    s.push(7);
    s.push(8);
    s.push(9);
    s.pop();
    s.pop();
    s.pop();
    s.pop();
    s.pop();
    s.pop();
    s.pop();
    s.pop();
    s.pop();
    s.pop();
}



Is This A Good Question/Topic? 0
  • +

Page 1 of 1