myqueue.h

来自「底层robocup3d源码。 suse10.0 kdevelop 开发.」· C头文件 代码 · 共 81 行

H
81
字号
#define QUEUE_SIZE   16
enum errorType {DOWNFLOW,OVER_FLOW,SUCCESS,ERROR_INDEX};
template<class T>
class queue
{
public:
	queue();
	int isEmpty()const;
	int isFull()const;
	errorType enQueue(const T );
	errorType delQueue();
	int size()const;
	errorType getFront(T &)const;
        errorType getAny(T &,int i)const;
private:
	int count,rear,front;
	 T data[QUEUE_SIZE];
};
template<class T>
queue<T>::queue()
{
	count=0;
	rear=front=0;
}
template<class T>
int queue<T>::isEmpty()const
{
	 if(rear==front)return 1;
	 else return 0;
}
template<class T>
int queue<T>::isFull()const
{
	 if((rear+1)%QUEUE_SIZE==front)return 1;
	 else return 0;
}
template<class T>
errorType queue<T>::delQueue()
{
	if(isEmpty())return DOWNFLOW;
	else
	{
		front=(front+1)%QUEUE_SIZE;
		count--;
		return SUCCESS;
	}
}
template<class T>
errorType queue<T>::enQueue(const T x)
{
	if(isFull())delQueue();
	rear=(rear+1)%QUEUE_SIZE;
	data[rear]=x;
	count++;
	return SUCCESS;
}
template<class T>
errorType queue<T>::getFront(T &x)const
{
	if(isEmpty())return DOWNFLOW;
	else
	{
		x=data[(front+1)%QUEUE_SIZE];
		return SUCCESS;
	}
}
template<class T>
errorType queue<T>:: getAny(T &x,int i)const
{
   if(i>count||i<1)return ERROR_INDEX;
   else 
   {
      x=data[(front+i)%QUEUE_SIZE];
      return SUCCESS;
   }
}
template<class T>
int queue<T>::size()const
{
	return count;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?