![]() |
|
|
Published: Wednesday, April 19, 2000 VBScript only provides a single built-in data type: the array. From that data type you can do a lot, though. Sometimes it's nice to have other data types, such as a linked list, stack, or queue. For those who are unfamiliar with these terms, let me take a moment to explain: List: - An ordered collection of items. Each item in a list is "connected" to one another through some means, and a global reference exists to the starting item in the list. That way, to visit any other item in the list, the user can sequentially step through the list. Queue: - An ordered collection of items that follows the following semantic: first in, first out. A queue has the following operations: enqueue and dequeue. When an item is enqueued, it is added to the queue, while a dequeue removes the item. The items are removed in the order they are added to the queue. So, if a queue had three items enqueued - A, B, and C - it would first dequeue A, then B, and then C. Stack: - A stack is similar to a queue except it follows a first in, last out semantic. A stack, like a queue, has two operations: push, which adds an item to the top of the stack, and pop, which removes an item from the top of the stack. A stack is like a stack of cafeteria trays. When taking a tray, you are removing the tray that was last put on the stack. Therefore, if we pushed A, B, and C onto a stack, when we popped the elements off, we'd get C, B, and A, in that order. This article focuses on creating an easy-to-use stack class using VBScript. If you are new to classes or unfamiliar with classes, let me strongly suggest that you read the following articles before continuing: (To use classes in VBScript, you must have the VBScript Scripting Engine Version 5.0 or greater. Check out Determining the Server-Side Scripting Language and Version to see what version of the VBScript you have and for instructions on downloading the latest version!)
As explained earlier in this article, a stack is a data structure that has a FILO (First
In Last Out) semantic and methods to permit the user to add elements
to the stack (
The
2.) It only supports a small subset of methods and properties a true list should support.
A "real" list data structure contains a number of elements linked together to form a list.
Rather than use this approach, we will use an array. To make things painfully easy, I will
be reusing some code presented in an earlier article, Dynamic Arrays.
Dynamic Arrays presented a class named
The
The code for the
Now that we have our list class, we are ready to create our stack class. As we'll
see in Part 2, creating the stack class is
insanely easy when using the
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
![]() |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||