Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- VERSION 1.0 CLASS
- BEGIN
- MultiUse = -1 'True
- END
- Attribute VB_Name = "Stack"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = False
- Attribute VB_Exposed = False
- Option Explicit
- Private StackValues()
- Private StackHead As Integer
- Public Sub Push(InputVariant)
- StackHead = StackHead + 1
- ReDim Preserve StackValues(1 To StackHead)
- StackValues(StackHead) = InputVariant
- End Sub
- Public Function Pop()
- If StackHead = 0 Then
- Pop = Null
- ElseIf StackHead = 1 Then
- StackHead = 0
- ReDim StackValues(1 To 1)
- Else
- Pop = StackValues(StackHead)
- StackHead = StackHead - 1
- ReDim Preserve StackValues(1 To StackHead)
- End If
- End Function
- Public Function Peek(Optional TargetAddress)
- If IsMissing(TargetAddress) Then
- Peek = StackValues(StackHead)
- Else
- If (TargetAddress <= 0) Or (TargetAddress > StackHead) Then
- Peek = -1
- Else
- Peek = StackValues(TargetAddress)
- End If
- End If
- End Function
- Public Sub Init(InputVariant)
- ReDim StackValues(1 To 1)
- StackHead = 1
- StackValues(1) = InputVariant
- End Sub
- Public Sub DumpToDebug()
- Dim Counter As Integer
- For Counter = 1 To StackHead
- Debug.Print Counter & ": " & StackValues(Counter)
- Next
- End Sub
- Public Function Depth() As Integer
- Depth = StackHead
- End Function
- Public Function InStack(ValueToCheck) As Boolean
- Dim Counter As Integer
- InStack = False
- For Counter = 1 To StackHead
- If StackValues(Counter) = ValueToCheck Then
- InStack = True
- End If
- Next
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement