📄 queuecricuity.c
字号:
#include "stdio.h"
#include "assert.h"
#include "string.h"
#define QUEUE_LEN 10
#define NULL_PTR 0
int q[QUEUE_LEN] = {0};
/*头*/
int spos = 0;
/*尾部*/
int rpos = 0;
void queueInit(void)
{
spos = rpos = 0;
}
int queueEmpty()
{
return spos == rpos;
}
int queueFull()
{
return (spos + 1)%QUEUE_LEN == rpos;
}
void queueStore(int data)
{
if (queueFull())
{
printf("\r\nQUEUE FULL");
return;
}
q[spos] = data;
spos = (spos + 1) %QUEUE_LEN;
}
void QueueGetFront(int * pdata)
{
assert(pdata);
if (queueEmpty())
{
printf("\r\nQUEUE NULL");
return;
}
*pdata = q[rpos];
rpos = (rpos + 1 )%QUEUE_LEN;
return;
}
void QueueTraver(void)
{
int i = rpos;
while(i != spos)
{
printf("\r\nQ DATA[%d] = %d", i,q[i]);
i = (i + 1)%QUEUE_LEN;
}
return;
}
int main(void)
{
int i = 0;
int data = 0;
for (i = 0; i < QUEUE_LEN; i++)
{
queueStore(i);
}
QueueTraver();
QueueGetFront(&data);
printf("\r\nGet Data[%d] = %d", rpos - 1,data);
QueueGetFront(&data);
printf("\r\nGet Data[%d] = %d", rpos - 1,data);
queueStore(100);
queueStore(101);
queueStore(102);
QueueTraver();
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -