home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC Gamer 4.5
/
1998-11_Disc_4.5.bin
/
ELINK
/
NSCOMM
/
STACK.JS
< prev
next >
Wrap
Text File
|
1997-10-22
|
1KB
|
75 lines
/* ==================================================================
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.