function Stack(size)
{
  this.sp    = 0;
  this.data  = new Array(size);
  this.push  = function(n) { this.sp++; this.data[this.sp] = n; }
  this.pop   = function()  { return this.data[this.sp--]; }
  this.depth = function()  { return this.sp; }
  this.tos   = function()  { return this.data[this.sp]; }
  this.nos   = function()  { return this.data[this.sp - 1]; }
  this.dup   = function()  { this.push(this.tos()); }
  this.drop  = function()  { this.sp--; }
  this.swap  = function()  { var a = this.nos();
                             this.data[this.sp - 1] = this.tos();
                             this.data[this.sp] = a;
                           }
  this.inc   = function()  { this.data[this.sp]++; }
  this.dec   = function()  { this.data[this.sp]--; }
  this.reset = function()  { this.sp = 0; }
}
/**********************************************************************
 * Stack object. Provides an easy way to create and work with LIFO
 * stacks.
 **********************************************************************/
Stack object. Provides an easy way to create and work with LIFO
stacks.
Stack object . Provides an easy way to create and work with LIFO stacks .
function Stack(size)
{
  this.sp    = 0;
  this.data  = new Array(size);
  this.push  = function(n) { this.sp++; this.data[this.sp] = n; }
  this.pop   = function()  { return this.data[this.sp--]; }
  this.depth = function()  { return this.sp; }
  this.tos   = function()  { return this.data[this.sp]; }
  this.nos   = function()  { return this.data[this.sp - 1]; }
  this.dup   = function()  { this.push(this.tos()); }
  this.drop  = function()  { this.sp--; }
  this.swap  = function()  { var a = this.nos();
                             this.data[this.sp - 1] = this.tos();
                             this.data[this.sp] = a;
                           }
  this.inc   = function()  { this.data[this.sp]++; }
  this.dec   = function()  { this.data[this.sp]--; }
  this.reset = function()  { this.sp = 0; }
}
function Stack ( size ) { this . sp = 0 ; this . data = new Array ( size ) ; this . push = function ( n ) { this . sp ++ ; this . data [ this . sp ] = n ; } this . pop = function ( ) { return this . data [ this . sp -- ] ; } this . depth = function ( ) { return this . sp ; } this . tos = function ( ) { return this . data [ this . sp ] ; } this . nos = function ( ) { return this . data [ this . sp - 1 ] ; } this . dup = function ( ) { this . push ( this . tos ( ) ) ; } this . drop = function ( ) { this . sp -- ; } this . swap = function ( ) { var a = this . nos ( ) ; this . data [ this . sp - 1 ] = this . tos ( ) ; this . data [ this . sp ] = a ; } this . inc = function ( ) { this . data [ this . sp ] ++ ; } this . dec = function ( ) { this . data [ this . sp ] -- ; } this . reset = function ( ) { this . sp = 0 ; } }
Stack object.
Stack object .