myqueue.h
#ifndef _MYQUEUE_H #define _MYQUEUE_H #include "bool.h" // ******************************************************************* // My queue class for integers (not a template class) // ******************************************************************* class myqueue { public: // constructors/destructor myqueue( ); // construct empty queue myqueue(const myqueue& Q); // copy constructor // (modify your mystack code) ~myqueue( ); // destructor // assignment const myqueue& myqueue::operator=(const myqueue &rhs); // (modify your mystack code) // accessors const int front( ) const; // return front (no dequeue) bool isEmpty( ) const; // return true if empty else false int length( ) const; // return number of elements in queue // modifiers void enqueue(const int & item ); // insert item (at rear) void dequeue( ); // remove first element void dequeue( int & item ); // combine front and dequeue void makeEmpty( ); // make queue empty private: struct nodetype { int info; nodetype * next; // pointer to next element nodetype (int D, nodetype *N): info (D), next (N) { } }; int mySize; // number of items currently in queue nodetype * myfront; // pointer to first element of queue nodetype * myback; // pointer to last element of queue }; // ******************************************************************* // Specifications for queue functions // // constructors/destructor // myqueue( ) // postcondition: the queue is empty // // myqueue ( const myqueue & R) // postcondition: the queue contains a copy of the elements of queue R // // ~myqueue( ) // postcondition: queue is destroyed // // accessors // const itemType & front( )const // precondition: queue has n >= 1 elements // postcondition: returns e1, queue is unchanged // // bool isEmpty( ) const // postcondition: returns true if queue is empty, false otherwise // // int length( ) const // precondition: queue has n >= 0 elements // postcondition: returns n // // modifiers: // void enqueue( const itemType & item ) // precondition: queue has n >= 0 elements // postcondition: item has been added to the end // // void dequeue( ) // precondition: queue has n >= 1 elements // postcondition: first element has been removed // // void dequeue( itemType & item ) // precondition: queue had n >= 1 elements // postcondition: first element has been removed and item == e1 // // void makeEmpty( ) // postcondition: queue is empty #include "myqueue.cpp" #endif