#if !defined H_QUEUE_DATA #define H_QUEUE_DATA // dynamic list of elements defined by 'Type' // can be used as a FIFO (first in first out) or just to store // an arbitrary number of elements class HBaseQueue { public: HBaseQueue(){nElements=0;} ~HBaseQueue(){} virtual void reset()=0; virtual void free()=0; virtual int find()=0; //get actual number of elements of the queue int noElements() {return nElements;} protected: int nElements; }; template class HQueueData : public HBaseQueue { public: HQueueData() : HBaseQueue() {first=last=current=0;} ~HQueueData() {free();} //return current element by reference and remove it from queue //(generalized FIFO function).Example x=remove(); //remove(); removes without returning anything Type& remove(); //find the specified element in the queue. Sets the pointer current to this element //returns 1 if element was found, otherwise 0. //Search starts at the next element after current. This allows to search //for a second appearance of the current element. int find(const Type &element); //search forward for a second appearance of the current element int find(); //reverse search // int rFind() //find an element within the search area defined by 'minEle' and 'maxEle'. //Sets the pointer current to the element found //requires that < and > operators are defined for the element int find(const Type &minEle,const Type &maxEle); //reset pointer current to the end of the list //thus, after reset is called, getNext returns the first element //and insert appends at the end. void reset() {current=last;} //get next or previous element, set current to next or previous Type& getNext() {current=current->next; return current->element;} Type& getPrevious() {current=current->previous; return current->element;} //deletes all members of the queue void free(); //append 'newElement' at the end of the queue (FIFO function) //does not affect the pointer 'current' int append(const Type &newElement); //insert 'newElement' behind current element. //The pointer current points to the newElement afterwards. int insert(const Type &newElement); protected: class HQueueElement { public: //creates an element of the queue, resets its pointer to the Null pointer //the latter is not necessary, if all functions of the queue are correctly //implemented. 'next' points to the next data element in the queue. //In case of the last element 'next' points to the first one. //Guess what previous does. HQueueElement(const Type &member) : element(member) {} Type element; HQueueElement *next, *previous; }; HQueueElement *first, *last, *current; }; #endif