Original: JavaScript Loop queue class

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.