// FILE: queue1.template // TEMPLATE CLASS IMPLEMENTED: queue (see queue1.h for documentation) // This file is included in the header file, and not compiled separately. // INVARIANT for the queue class: // 1. The number of items in the queue is in the member variable count; // 2. For a non-empty queue, the items are stored in a circular array // beginning at data[front] and continuing through data[rear]. // The array's total capacity of the array is CAPACITY. // 3. For an empty array, rear is some valid index, and front is // always equal to next_index(rear). // #include // Provides assert namespace main_savitch_8B { template const typename queue::size_type queue::CAPACITY; template queue::queue( ) { count = 0; first = 0; last = CAPACITY - 1; } template Item queue::front( ) const // Library facilities used: cassert { assert(!empty( )); return data[first]; } template void queue::pop( ) // Library facilities used: cassert { assert(!empty( )); first = next_index(first); --count; } template void queue::push(const Item& entry) // Library facilities used: cassert { assert(size( ) < CAPACITY); last = next_index(last); data[last] = entry; ++count; } }