In Part 1 we looked at what a stack data structure is,
exactly, and what semantics and methods it needs to include. Also, we looked at creating a
WeakList class using the
DynamicArray class presented in an earlier
article (Dynamic Arrays). In this part, we will look at
the code for our stack class.
Recall that a stack needs to implement the following functions:
push. To make our stack class even more useful, we'll also add a
property and a
peek method. (The
peek method will return the value
at the top of the stack without altering the stack in any way.) Our stack class will contain
a single member variable, an instance of the
WeakList class. The event handlers
of the class simple instantiate the
WeakList class and clean up afterwards.
Note that the
WeakList class definition, which was stored in a file named
WeakList.Class.asp was imported via a server-side include.
The member variable
wlList serves as an instance of the
class. All of the methods and properties of the stack class will use this single member
variable. By doing so, the code for the stack class is short and easy to the point of
Following is the methods and properties for the stack class:
Pretty easy, eh? All of our methods and properties are only one line long! Neat-o.
This class definition should be placed in its own file,
Stack.Class.asp, for example.
How about an example of using the stack class? You can also view an
on-line demo of the code displayed below.
Well, that wraps it up! Hopefully you found this stack class and/or
useful. Feel free to use these classes in your ASP projects.
WeakList.Class.aspin text format
Stack.Class.aspin text format