/*
 * Script for lifo queues of objects
 */

function createLifoQ()
{ 
  myQ = new Array();
  myQ.clear = function() { this.length = 0; };  
  myQ.peek = function() { if (this.length > 0) { return this[this.length-1]; } else { return undefined; }; };
  return myQ;
}

function createHistoryQ(maxL)
{
  myQ = new Array()
  myQ.maxLength = (maxL)?((maxL < 1)?1:maxL):20;
  myQ.point = -1;
  myQ.addNew = function(newObj)
    {
      if ((this.point + 1) < this.length) 
      { 
        this.splice(this.point + 1); 
        this.length = this.point + 1 
      }
      if (this.length >= this.maxLength) { this.shift(1); }     
      this.push(newObj);
      this.point = this.length - 1;
    }
  myQ.foward = function() 
    { 
      if ((this.length - this.point) = 1) return null;
      this.point++;
      return this[this.point];
    } 
  myQ.back = function()
    {
      if (this.point = 0) return null;
      this.point--;
      return this[this.point];
    }      
  myQ.current = function() { return this[this.point] ; }
  myQ.clear = function() { this.length = 0; };
  return myQ;  
}
