general/mini/
csstack.pro
Function: csstack Purpose: This procedure implements the push,pop,& peek methods for a traditional computer science data structure: the stack. It is a basic LIFO data structure. Advantages over array: 1. store heterogenous elements of any type in a stack. 2. stack can grow as large as memory and you don't need to know how big it will be in advance 3. You don't need to worry about how the data is stored Disadvantages over array: 1. You can't directly apply operations to the data structure 2. You are forced to use abstraction Inputs: arg1:the meaning of the argument varies with syntax arg2:the meaning of the argument varies with syntax Keywords: push(optional) : set this to add an item to the stack and return the modified stack pop(optional) : set this to remove an item from the stack and return the modified stack peek(optional) : set this to return the top element on the stack length(optional): set this if you want to return the length free(optional): set this if you want to free the vector's memory without creating a leak, it will return the number of elements free'd If no keywords are set, default behavior is push Outputs: If push or pop are set it returns the modified stack If peek is set it returns the top element on the stack If length or free are set it returns a number of items Syntax(each method is followed by examples): push stk = csstack(item) stk = csstack(item,stk) ;stk can be defined or not stk = csstack(item,stk,/push) pop: stk = csstack(stk,/pop) ;must have at least one element peek: item = csstack(stk,/peek) ;must have at least one element length: length = csvector(stk,/length) free: num = csvector(stk,/free) NOTES: in the event of overflow during add the vector.a component will double in size Push stores a copy of the element not the element itself If you want to do manual lengths and reads you can look at the code, but I would recommend against cause you are violating abstraction which means the internal representation could change and invalidate your code. This might be worth writing in O.O. idl as well To get type flexibility it uses a pointer for every object Thus if you aren't careful this function will eat your system memory for breakfast. Use heap_gc to clean up if you are running out of memory. $LastChangedBy: pcruce $ $LastChangedDate: 2008-09-12 16:21:16 -0700 (Fri, 12 Sep 2008) $ $LastChangedRevision: 3487 $ $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/trunk/general/mini/csstack.pro $
Routines
File attributes
Modification date: | Thu Feb 13 16:43:50 2014 |
Lines: | 92 |