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: pop and
push. To make our stack class even more useful, we'll also add a Count
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 WeakList
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
lunacy.
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 WeakList
useful. Feel free to use these classes in your ASP projects.
Happy Programming!
Attachments:
WeakList.Class.asp in text formatStack.Class.asp in text format



