++



         


PeekbackStack IntArray , ? ? .

  ߔ. PeekbackStack IntArray  Ҕ. PeekbackStack IntArray . Ҕ, , , . . IntArray PeekbackStack. PeekbackStack :

class PeekbackStack {

private:

const int static bos = -1;

public:

explicit PeekbackStack( int size ) :

stack( 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() )

/* */ ;

return stack[ _top-- ];

}

void push( int value ) {

if ( full() )

/* */ ;

stack[ ++_top ] = value;

}

bool peekback( int index, int &value ) const;

private:

int _top;

IntArray stack;

};

inline bool

PeekbackStack::

peekback( int index, int &value ) const

{

if ( empty() )

/* */ ;

if ( index < 0 || index > _top )

{

value = stack[ _top ];

return false;

}

value = stack[ index ];

return true;

}

, Ҕ , :

  • - , ;
  • , ( 18.3.4);
  • , PeekbackStack, , . , ( ).



  •