00001 #ifndef __J2K__Linked_Queue_HPP__
00002 #define __J2K__Linked_Queue_HPP__
00003
00004 #include <j2k/Fred/Standard.hpp>
00005 #include <j2k/DataType/Link/SLink.cpp>
00006
00007 class LinkedQueue {
00008
00009 public:
00010 inline LinkedQueue()
00011 : front( NULL ), rear( NULL ) { }
00012
00013 inline virtual ~LinkedQueue()
00014 {
00015 clear();
00016 }
00017
00018 void clear();
00019 void enqueue( Elem* item );
00020 Elem* dequeue();
00021
00022 inline Elem* firstValue() const
00023 {
00024 assert( !isEmpty() );
00025 return front->element;
00026 }
00027
00028 inline BOOL isEmpty() const
00029 {
00030 return front == NULL;
00031 }
00032
00033 inline BOOL isFilled() const
00034 {
00035 return front != NULL;
00036 }
00037
00038 private:
00039 SLink* front;
00040 SLink* rear;
00041 };
00042
00043 void LinkedQueue::clear()
00044 {
00045 while( front != NULL )
00046 {
00047 rear = front;
00048 front = front->next;
00049 delete rear;
00050 }
00051 rear = NULL;
00052 }
00053
00054
00055 void LinkedQueue::enqueue( Elem* item )
00056 {
00057 if ( rear != NULL )
00058 {
00059 rear = rear->next = new SLink( item, NULL );
00060 }
00061 else
00062 {
00063 front = rear = new SLink( item, NULL );
00064 }
00065 }
00066
00067 Elem* LinkedQueue::dequeue()
00068 {
00069 assert( !isEmpty() );
00070
00071 Elem* temp = front->element;
00072 SLink* ltemp = front;
00073 front = front->next;
00074
00075 delete ltemp;
00076
00077 if ( front == NULL )
00078 {
00079 rear = NULL;
00080 }
00081
00082 return temp;
00083 }
00084
00085 #endif // End of LinkedQueue.hpp