静态环形队列(C语言)

 

typedef struct                                     //数据内容根据实际可以随意变更
{
	int a;
	int b;
	int c;
	char str[100];
}DataDef



#define BUFFER_LEN 20                                //环形队列长度
static int Read  = 0;                                //读计数
static int Write = 0;                                //写计数
static DataDef DataBuff[BUFFER_LEN];                 //环形队列


static int BufferFull(void)                          //环形队列满
{
	return (Read == ((Write + 1) % BUFFER_LEN));
}

static int BufferEmpty(void)                         //环形队列空
{
	return (Read == Write);
}

static void PutDataToBuffer(DataDef *data)           //一组数据写入队列
{
	if (!BufferFull())
	{
		DataBuff[Write] = *data;
		Write = (Write + 1) % BUFFER_LEN;
	}
}


static int GetDataFromBuffer(DataDef *data)         //从队列读出一组数据
{
	if (!BufferEmpty())
	{
		*data= DataBuff[Read];
		Read = (Read + 1) % BUFFER_LEN;
		return 1;
	}
	else
	{
		return 0;
	}
}

上一篇:快速熟悉 Oracle AWR 报告解读


下一篇:关于spark 读取 elasticsearch时,空字符串被转成null的问题排查与解决