Need to scroll up to a certain amount of information to get this
var leescirclequeue=function (size) {//queue array var _queue=[]; Team Head index VAR _front=0; Team Tail index var _rear=0; The number of elements Var _length=0; The memory size of the queue, but the actual usable size is _capacity-1 var _capacity = size; add element this. Push=function (item) {var nIndex = Getnextrearindex (); _queue[nindex] = Item; if (_length < _capacity) _length++; }//Remove head element this. Pop=function () {if (_length > 0) {_length--; _front++; if (_front = = _capacity) _front = 0; } if (_length = = 0) {_front = _rear = 0; }}//Get the full contents of this. Getallitem=function () {var tmp = []; for (var i = 0; i < _length; i++) {Tmp[i] = _queue[(_front + i)% _capacity]; } return TMP; }//Gets the next index function Getnextrearindex () {if (_length = = _capacity)//full {_rear = (_rear + 1)% _capacity; _front = (_rear + 1)% _capacity; } else {if (_length > 0) _rear = (_rear + 1)% _capacity; else {_front = _rear = 0; }} return _rear; }};
Original: JavaScript Loop queue class