前端之家收集整理的这篇文章主要介绍了
VB简单堆栈类的实现,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
Private Stack() As String
Private itemCount As Long
Private Sub Class_Initialize()
ReDim Stack(0)
End Sub
Public Sub Push(ByVal inString As String)
ReDim Preserve Stack(itemCount + 1)
Stack(itemCount + 1) = inString
itemCount = itemCount + 1
End Sub
Public Function Pop() As String
If itemCount >= 1 Then
Pop = Stack(itemCount)
ReDim Preserve Stack(itemCount - 1)
itemCount = itemCount - 1
Else
Pop = ""
End If
End Function
Public Function Peek() As String
Peek = Stack(itemCount)
End Function
Sub Clear()
itemCount = 0
ReDim Stack(itemCount)
End Sub
Public Function Count()
Count = itemCount
End Function