home *** CD-ROM | disk | FTP | other *** search
/ PC Users 1998 June / Cd Pc Users 9.iso / prog / inst / baslibs / clsstack.cls < prev    next >
Encoding:
Text File  |  1996-12-04  |  1.3 KB  |  78 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "clsStack"
  6. Attribute VB_Creatable = False
  7. Attribute VB_Exposed = False
  8. Option Explicit
  9.  
  10. ' A simple Stack class.
  11.  
  12.  
  13. ' Private Data
  14. Private vData As New Collection
  15.  
  16.  
  17. Public Sub Clear()
  18.    Set vData = New Collection
  19. End Sub
  20.  
  21.  
  22. '
  23. ' Returns the number of items in the stack.
  24. '
  25. Property Get Count() As Long
  26.    Count = vData.Count
  27. End Property
  28.  
  29.  
  30.  
  31. '
  32. '  Returns the value of the next item on the
  33. '  stack without removing the item from the
  34. '  stack.
  35. '
  36. Public Function Peek() As Variant
  37.    If vData.Count = 0 Then
  38.       Peek = Null
  39.    Else
  40.       If VarType(vData.Item(1)) = vbObject Then
  41.          Set Peek = vData(1)
  42.       Else
  43.          Peek = vData(1)
  44.       End If
  45.    End If
  46. End Function
  47.  
  48. '
  49. '  Removes and returns the next item from
  50. '  the stack.
  51. '
  52. Public Function Pop() As Variant
  53.    If vData.Count = 0 Then
  54.       Pop = Null
  55.    Else
  56.       If VarType(vData(1)) = vbObject Then
  57.          Set Pop = vData(1)
  58.       Else
  59.          Pop = vData(1)
  60.       End If
  61.       vData.Remove 1
  62.    End If
  63. End Function
  64.  
  65.  
  66.  
  67.  
  68. '
  69. '  Adds an item to the Stack
  70. '
  71. Public Sub Push(v As Variant)
  72.    If vData.Count = 0 Then
  73.       vData.Add v
  74.    Else
  75.      vData.Add v, , 1
  76.    End If
  77. End Sub
  78.