您的位置:首页 > 编程语言 > VB

VB简单堆栈类的实现

2013-04-21 19:09 155 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: