- /*
- *使用数组作为数据成员来实现栈
- *倒序使用数组:插入时从末尾插入,弹出时从末尾弹出
- *Stack( ) 构造函数
- *top( ) 获得栈顶的元素,但不删除
- *empty( ) 判断是否为空
- *display( ) 显示栈内的数据
- *push( ) 入栈
- *pop( ) 出栈
- */
- #ifndef ARRAY_STACK_H
- #define ARRAY_STACK_H
- #include <iostream>
- const int STACK_CAPACITY=1024;
- typedet int elementType;
- class Stack
- {
- public:
- Stack( );
- bool empty( ) const;
- void display( osteam & out ) const;
- elementType top( ) const;
- void push( const elementType& value );
- void pop( );
- private:
- elementType m_array[ STACK_CAPACITY ];
- int m_size;
- int m_top; //指向栈顶
- };
- ostream& opeartor <<(ostream & out,Stack& sstack ) ;
- #endif