peekbackstack.h
来自「C++ Primer(第三版)的随书源代码」· C头文件 代码 · 共 45 行
H
45 行
#include "IntArray.h"
class PeekbackStack : public IntArray {
private:
// const int static bos = -1;
const int static bos;
public:
// explicit PeekbackStack( int size )
PeekbackStack( int size ) : IntArray( size ), _top( bos ) {}
bool empty() const { return _top == bos; }
bool full() const { return _top == size()-1; }
int top() const { return _top; }
int pop() {
if ( empty() ) /* handle error condition */ ;
return _ia[ _top-- ];
}
void push( int value ) {
if ( full() ) /* handle error condition */ ;
_ia[ ++_top ] = value;
}
bool peekback( int index, int &value ) const;
private:
int _top;
};
inline bool
PeekbackStack::
peekback( int index, int &value ) const
{
if ( empty() ) /* handle error condition */ ;
if ( index < 0 || index > _top ) {
value = _ia[ _top ];
return false;
}
value = _ia[ index ];
return true;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?