满/空判断演示

环形缓冲区状态

0
写指针
0
读指针
0
数据量
缓冲区状态
可写入
可读取

判断方法对比

方法一:计数器法
bool isEmpty() {
  return count == 0;
}

bool isFull() {
  return count == SIZE;
}
isEmpty: true
方法二:指针比较法
bool isEmpty() {
  return head == tail;
}

bool isFull() {
  return (head + 1) % SIZE == tail;
}
isEmpty: true