////////////////////////////////////////////////////////////////////// // // SQUEUE.H // // class Queue // // RomaNets Text Windows Library (RTWL) // // version 0.6 // // Herbert Schildt // Sergey RomaNets // #ifndef __SQUEUE_H #define __SQUEUE_H typedef int bool; #define true 1 #define false 0 //////////////////////////////////////////////////////////// template class Queue //////////////////////////////////////////////////////////// { private: T *q; int sloc; // store int rloc; // retrieve int length; public: Queue( int size); ~Queue() { delete [] q;} void store(T i); T retrieve(); bool isFull(); }; // ......................................................... template Queue::Queue( int size) { size++; q = new T[size]; length = size; sloc = rloc = 0; } // ......................................................... template void Queue::store(T i) { q[sloc] = i; sloc++; if (sloc==length) sloc = 0; } // ......................................................... template T Queue::retrieve() { if (rloc == length) rloc = 0; if (rloc == sloc) return 0; rloc++; return q[rloc-1]; } // ......................................................... template bool Queue::isFull() { if ( sloc+1 == rloc || (sloc+1==length && !rloc)) return true; // queue is full else return false; } #endif /* __SQUEUE_H */