A stack is a restricted form of a list. All insertions and deletions occur at one end of the list.
The stack data type defines three operations:
The stack is a LIFO, or Last-In, First-Out, data type. This means that data enters and exits from the same end of the list. An example of a stack is a spring loaded plate dispenser in a cafeteria. The last plate placed in the dispenser is the first one removed. This class is implemented using an array based approach. When the array becomes full, the array is grown by the amount specified in the GrowBy property. This class supports object variables in addition to the standard text and numeric types.
|(Declarations)||Declarations||Declarations and private variables for the CStack class.|
|GrowBy||Property||Get the amount the stack grows by when it needs to be reallocated. The default value is ten. If you know that hundreds of items are going to placed on the stack, you can increase this number to reduce the number of ReDims of the mavarData array.|
|Class_Initialize||Initialize||Set initial values.|
|Pop||Method||Removes the topmost item off the stack, and places it in the varData variable.|
|Push||Method||Pushes the data specified in varData on the top of the stack. If the stack is full, it grows by the amount specified by the GrowBy property.|
|Top||Method||Get the item on the top of the stack. This function differs from pop in that it does not remove the item from the stack.|
' Example of CStack ' ' To try this example, do the following: ' 1. Create a new form ' 2. Create a command button named 'cmdTest' ' 3. Paste all the code from this example to the new form's module. ' 4. Run the form Private Sub cmdTest_Click() Dim Stack As CStack Dim varData As Variant Dim intCounter As Integer Set Stack = New CStack ' Push 100 items onto the stack For intCounter = 1 To 100 varData = "Item" & intCounter Stack.Push varData Next intCounter ' Pop all the items off the stack Do While Stack.Pop(varData) Debug.Print varData Loop End Sub
The source code in Total Visual Sourcebook includes modules and classes for Microsoft Access, Visual Basic 6 (VB6), and Visual Basic for Applications (VBA) developers. Easily add this professionally written, tested, and documented royalty-free code into your applications to simplify your application development efforts.
Total Visual SourceBook is written for the needs of a developer using a source code library covering the many challenges you face. Countless developers over the years have told us they learned some or much of their development skills and tricks from our code. You can too!
Supports Access/Office 2016, 2013, 2010 and 2007, and Visual Basic 6.0!
"The code is exactly how I would like to write code and the algorithms used are very efficient and well-documented."
Van T. Dinh, Microsoft MVP