Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is a quick mockup of the code you could use (it probably isn't working and has bugs in it, but it shows the way it could be done):</p> <pre><code>var CircularQueueItem = function(value, next, back) { this.next = next; this.value = value; this.back = back; return this; }; var CircularQueue = function(queueLength){ /// &lt;summary&gt;Creates a circular queue of specified length&lt;/summary&gt; /// &lt;param name="queueLength" type="int"&gt;Length of the circular queue&lt;/type&gt; this._current = new CircularQueueItem(undefined, undefined, undefined); var item = this._current; for(var i = 0; i &lt; queueLength - 1; i++) { item.next = new CircularQueueItem(undefined, undefined, item); item = item.next; } item.next = this._current; this._current.back = item; } CircularQueue.prototype.push = function(value){ /// &lt;summary&gt;Pushes a value/object into the circular queue&lt;/summary&gt; /// &lt;param name="value"&gt;Any value/object that should be stored into the queue&lt;/param&gt; this._current.value = value; this._current = this._current.next; }; CircularQueue.prototype.pop = function(){ /// &lt;summary&gt;Gets the last pushed value/object from the circular queue&lt;/summary&gt; /// &lt;returns&gt;Returns the last pushed value/object from the circular queue&lt;/returns&gt; this._current = this._current.back; return this._current.value; }; </code></pre> <p>using this object would be like:</p> <pre><code>var queue = new CircularQueue(10); // a circular queue with 10 items queue.push(10); queue.push(20); alert(queue.pop()); alert(queue.pop()); </code></pre> <p>You could of course implement it using array as well with a class that would internally use an array and keep a value of the current item index and moving that one.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload