SHARE
TWEET

ascagnel

a guest Nov 7th, 2009 287 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "Stack"
  6. Attribute VB_GlobalNameSpace = False
  7. Attribute VB_Creatable = False
  8. Attribute VB_PredeclaredId = False
  9. Attribute VB_Exposed = False
  10. Option Explicit
  11. Private StackValues()
  12. Private StackHead As Integer
  13. Public Sub Push(InputVariant)
  14.     StackHead = StackHead + 1
  15.     ReDim Preserve StackValues(1 To StackHead)
  16.     StackValues(StackHead) = InputVariant
  17. End Sub
  18. Public Function Pop()
  19.     If StackHead = 0 Then
  20.         Pop = Null
  21.     ElseIf StackHead = 1 Then
  22.         StackHead = 0
  23.         ReDim StackValues(1 To 1)
  24.     Else
  25.         Pop = StackValues(StackHead)
  26.         StackHead = StackHead - 1
  27.         ReDim Preserve StackValues(1 To StackHead)
  28.     End If
  29. End Function
  30. Public Function Peek(Optional TargetAddress)
  31.     If IsMissing(TargetAddress) Then
  32.         Peek = StackValues(StackHead)
  33.     Else
  34.         If (TargetAddress <= 0) Or (TargetAddress > StackHead) Then
  35.             Peek = -1
  36.         Else
  37.             Peek = StackValues(TargetAddress)
  38.         End If
  39.     End If
  40. End Function
  41. Public Sub Init(InputVariant)
  42.     ReDim StackValues(1 To 1)
  43.     StackHead = 1
  44.     StackValues(1) = InputVariant
  45. End Sub
  46. Public Sub DumpToDebug()
  47.     Dim Counter As Integer
  48.     For Counter = 1 To StackHead
  49.         Debug.Print Counter & ": " & StackValues(Counter)
  50.     Next
  51. End Sub
  52. Public Function Depth() As Integer
  53.     Depth = StackHead
  54. End Function
  55. Public Function InStack(ValueToCheck) As Boolean
  56.     Dim Counter As Integer
  57.     InStack = False
  58.     For Counter = 1 To StackHead
  59.         If StackValues(Counter) = ValueToCheck Then
  60.             InStack = True
  61.         End If
  62.     Next
  63. End Function
RAW Paste Data
Top