// FILE: stack3.template // TEMPLATE CLASS IMPLEMENTED: stack (see stack3.h for documentation) // This file is included in the header file, and not compiled separately. // INVARIANT for the stack class: // 1. The number of items in the stack is in the member variable used. // 2. The actual items of the stack are stored in a partially-filled // array data[0]..data[used-1]. The stack elements appear from the // bottom (at data[0]) to the top (at data[used-1]). #include // Provides assert namespace main_savitch_7A { template const typename stack::size_type stack::CAPACITY; template void stack::push(const Item& entry) // Library facilities used: cassert { assert(size( ) < CAPACITY); data[used] = entry; ++used; } template void stack::pop( ) // Library facilities used: cassert { assert(!empty( )); --used; } template Item& stack::top( ) // Library facilities used: cassert { assert(!empty( )); return data[used-1]; } template const Item& stack::top( ) const // Library facilities used: cassert { assert(!empty( )); return data[used-1]; } }