++




: Stack - 2


if ( empty() )

return false;

top_value = _stack[ --_top ];

cout << "iStack::pop(): " << top_value << endl;

return true;

}

bool iStack::push( int value ) {

cout << "iStack::push( " << value << " )\n";

if ( full() )

return false;

_stack[ _top++ ] = value;

return true;

}

, display(), . :

( 0 )

  0, 1, 2 3  display() :

( 4 )( bot: 0 1 2 3 :top )

display():

void iStack::display() {

cout << "( " << size() << " )( bot: ";

for ( int ix = 0; ix < _top; ++ix )

cout << _stack[ ix ] << " ";

cout << " :top )\n";

}

. for 50 . (2, 4, 6, 8 ..) . , 5 (5, 10, 15...), . , 10 (10, 20, 30...), .

#inc1ude <iostream>

#inc1ude "iStack.h"

int main() {

iStack stack( 32 ) ;

stack.display();

for ( int ix = 1; ix < 51; ++ix )

{

if ( ix%2 == 0 )

stack.push( ix );

if ( ix%5 == 0 )

stack.display();

if ( ix%10 == 0 ) {

int dummy;

stack.pop( dummy ); stack.pop( dummy );

stack.display();

}

}

:

( 0 )( bot: :top )

iStack push( 2 )

iStack push( 4 )

( 2 )( bot: 2 4 :top )

iStack push( 6 )

iStack push( 8 )

iStack push ( 10 )