let size = 0;
let start = 0; //start是新去除的数所在的位置
let end = 0; //end是新插入的数应放置的位置
const maxLength = 3; //固定长度
//start和end无关系,它俩都只和size有关系
function push(arr, num) {
if (size === maxLength) {
throw 'queue is full';
}
size++;
arr[end] = num;
end = end === maxLength - 1 ? 0 : end + 1;
}
function poll(arr) {
if (size === 0) {
throw 'queue is empty';
}
size--;
let tmp = start;
start = start === maxLength - 1 ? 0 : start + 1;
return arr[tmp];
}
11-29
225