Chapter 7


7.1 Introduction to stack

<1> The specification of Iterafor class

    template  <Class Item>
    class Bag_Iterator()  {
         public :
              Bag_Iterator() ;
              vold attach (const Bag <Item>& ) ;
              vold adcance() ;
              Item current() const ;
              bool is_item() const ;

<2> Usage

    Bag <Int>  foo ;
    Bag_Iterator <Int>  iterator ;
    - - - - - - - - -
    for ( iterafor.attach(foo) ; iterator.is_item() ; iterafor.advance() )
          cout << iterafor.current() << endl ;
also the following works
    Bag_Iterafor <Int>  itr1  itr2 ;
    for ( itr1.attach(foo) ; itr1.is_item() ; itr(advance() )
          for (itr2.attach(foo) ; itr2.is_item() ; itr2.advance() ) {
                    - - - -
          }
  1. Stack :
    	a data structer of order entries such 
    	that entries can only be insented anol removed
    	at one end (called top)

  2. LIFO :
    	last-in / first out

  3. The Stack ADT -- specification and documentation
    1. specification (see p309)
      1. template class : stacks of integers float
      2. capcity capcity of stack (fixed-size first)
      3. member function push : push an item to stack pop : pop on item from stack peek : peek the top item size : obtain the total no of items is.empty : examine if stack is empty
      4. Stack errors stack underflow : pop from on empty stack stack overfloew : push into a full stack
    2. documentation (page 309)
  4. example reversing a word
               apple -> elppa