/* ==================================================================

FILE:   Stack.js

DESCR:  Stack object.

NOTES:  

================================================================== */



/*

DESCR:   Stack class.

PARAMS:

RETURNS:

NOTES:

*/

function stack()

{

   this.pointer = -1

   this.topItem

   this.aItems = new Array



   this.push    = push

   this.pop     = pop

   this.isEmpty = isEmpty

   this.clear   = clear

}



   /*

   DESCR:   

   PARAMS:  item  A variable of any type.

   RETURNS: 

   NOTES:   

   */

   function push( item )

   {

      this.topItem = item

      this.aItems[ ++this.pointer ] = item

   }



   /*

   DESCR:

   PARAMS:

   RETURNS: The item.

   NOTES:

   */

   function pop()

   {

      if ( this.isEmpty() ) return null

      this.topItem = this.aItems[ this.pointer - 1 ]

      return this.aItems[ this.pointer-- ]

   }



   /*

   DESCR:   Empties the stack.

   PARAMS:

   RETURNS:

   NOTES:

   */

   function clear()

   {

      this.pointer = -1

      this.topItem = null

   }



   /*

   DESCR:

   PARAMS:

   RETURNS: true if the stack contains no members; false otherwise.

   NOTES:

   */

   function isEmpty()

   {

      return ( this.pointer < 0 ? true : false )

   }



// End class definition: stack.



