⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 myqueue.h~

📁 底层robocup3d源码。 suse10.0 kdevelop 开发.
💻 H~
字号:
#ifndef MSPACECOMMAND_H
#define MSPACECOMMAND_H

#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;
}

#endif

⌨️ 快捷键说明

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