⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 peekbackstack.h

📁 适合中高级学习的人参考使用的c++程序代码
💻 H
字号:
#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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -