/* -*- mode: c++; c-file-style: raknet; tab-always-indent: nil; -*- */ /* QueueLinkedList ADT - By Kevin Jenkins (http://www.rakkar.org) Initilize with the following structure QueueLinkedList Has the following member functions push - adds an element to the top of the queue pop - returns the bottom element from the queue and removes it. Result undefined if queue empty peek - returns the bottom element from the queue. Result undefined if queue empty end_peek - Lets you see the item you most recently added to the queue size - returns the size of the queue compress - reallocates memory to fit the number of elements. Best used when the number of elements decreases clear - empties the queue and returns storage The assignment and copy constructors are defined EXAMPLE QueueLinkedList A; A.push(5); A.push(10); A.peek(); // Returns 5 A.pop(); // Returns 5 A.peek(); // Returns 10 A.pop(); // Returns 10 // At this point the queue is empty NOTES The default initial allocation size is 1 This queue uses a linked list to contain elements */ #ifndef __QUEUE_LINKED_LIST_H #define __QUEUE_LINKED_LIST_H #include "LinkedList.h" ////#include "MemoryManager.h" namespace BasicDataStructures { template class QueueLinkedList { public: QueueLinkedList(); QueueLinkedList( const QueueLinkedList& original_copy ); bool operator= ( const QueueLinkedList& original_copy ); QueueType pop( void ); QueueType& peek( void ); QueueType& end_peek( void ); void push( const QueueType& input ); const unsigned int size( void ); void clear( void ); void compress( void ); private: LinkedList data; }; template QueueLinkedList::QueueLinkedList() { // hi } template inline const unsigned int QueueLinkedList::size() { return data.size(); } template inline QueueType QueueLinkedList::pop( void ) { data.beginning(); return ( QueueType ) data.pop(); } template inline QueueType& QueueLinkedList::peek( void ) { data.beginning(); return ( QueueType ) data.peek(); } template inline QueueType& QueueLinkedList::end_peek( void ) { data.end(); return ( QueueType ) data.peek(); } template void QueueLinkedList::push( const QueueType& input ) { data.end(); data.add( input ); } template QueueLinkedList::QueueLinkedList( const QueueLinkedList& original_copy ) { data = original_copy.data; } template bool QueueLinkedList::operator= ( const QueueLinkedList& original_copy ) { if ( ( &original_copy ) == this ) return false; data = original_copy.data; } template void QueueLinkedList::clear ( void ) { data.clear(); } } // End namespace #endif