peterschussheim
10/27/2016 - 9:09 PM

queue

queue

///funcational classing
var Queue = function() {
    var instance = {},
        head = 0,
        tail = 0;
}

instance.enqueue = function(value) {
    storage[tail] = value;
    tail += 1;
};

instance.dequeue = function() {
    if (tail > start) { ///check if the queue is empty
        var result = storage[start];
        delete storage[head];
        head += 1;
        return result;
};

instance.size = function() {
    return end - start;
};

queue

This Gist was automatically created by Carbide, a free online programming environment.

You can view a live, interactive version of this Gist here.