数据结构 {循环队列}
循环队列
#define SIZE 4
struct queue{
int head, tail;
int que[SIZE];
};
void init(struct queue* q){
q->head = q->tail = 0;
}
int isEmpty(const struct queue* q) const {
return q->head == q->tail;
}
int isFull(const struct queue* q) const {
return (q->tail + 1) % SIZE == q->head;
}
void push(struct queue* q, int val){
q->que[q->tail++] = val;
q->tail = q->tail % SIZE;
}
int pop(struct queue* q){
int res = q->que[q->head++];
q->head = q->head % SIZE;
return res;
} 相关推荐
ipqtjmqj 2020-03-23
hanyujianke 2020-02-25
niushao 2020-01-10
xx0cw 2019-12-10
whtqsq 2019-09-07
zzpdljd 2019-08-02
meridian00 2019-07-01
lickylin 2019-07-01
基尔霍夫的猫 2019-06-28
hanyujianke 2017-10-27
PHP100 2019-03-28
大故事家 2018-05-13
btr的心灵鸡杂汤 2018-05-04
大故事家 2017-11-29
BAT 批处理程序 2017-06-19