// Computer Science 367, Section 3, Fall 1997 // Instructor: Michael Siff (siff@cs.wisc.edu) // // // FILE: queue.C // // // A queue template class using a linked-list List template class. // // // INVARIANT for Queue: // // Keep the cursor of the underlying list at the head of the list and thus // at the front of the queue. Dequeue will call reset, current, and // remove. Enqueue will call append. #include // Provides assert #include // Provides size_t // CONSTANT MEMBER FUNCTIONS // ------------------------- template size_t Queue::size() const { return (rep.length()); } template bool Queue::isEmpty() const { return(rep.isEmpty()); } template bool Queue::isFull() const { return(rep.isFull()); } // MODIFICATION MEMBER FUNCTIONS // ----------------------------- template void Queue::enqueue(const Item& it) // Places it on the back of the queue. { assert(!isFull()); rep.append(it); } template Item Queue::dequeue() // Removes and returns the item off the front of the queue. { assert(!isEmpty()); rep.reset(); // make sure the cursor is at the front Item result = rep.current(); rep.remove(); return result; }