Created
February 26, 2010 18:32
-
-
Save atuttle/316000 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfcomponent hint="A stack class that makes working with arrays as stacks clean and simple"> | |
<cfscript> | |
//private data | |
variables.data = arrayNew(1); | |
function init(){ | |
if (!structIsEmpty(arguments)){ | |
if (isArray(arguments[1])){//handle array source data | |
variables.data = arguments[1]; | |
}else if (isSimpleValue(arguments[1])){//handle string source data | |
variables.data = listToArray(arguments[1]); | |
} | |
} | |
return( this ); | |
} | |
function push(newVal){ | |
arrayAppend(variables.data, arguments.newVal); | |
} | |
function pop(){ | |
var rtn = ''; | |
if (isEmpty()) | |
return ''; | |
rtn = variables.data[arrayLen(variables.data)]; | |
arrayDeleteAt(variables.data, arrayLen(variables.data)); | |
return( rtn ); | |
} | |
function top(){ | |
if (!isEmpty()) | |
return( variables.data[arrayLen(variables.data)] ); | |
else | |
return ''; | |
} | |
function isEmpty(){ | |
return( arrayLen(variables.data) == 0 ); | |
} | |
</cfscript> | |
</cfcomponent> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment