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

vbs - 一个简单的栈 -- 只能存储类对象

2016-07-25 20:59 591 查看
'----------------------------堆栈-------------------------------------
Const MAX_STACK = 1024
Class MyStack
Private int_Top  '声明变量top
Private int_Bottom  '声明变量now
Private strStack(1024)  '声明堆数组

'Initialize 构建函数
Private Sub Class_Initialize
top = 0
bottom = 0
End Sub

'定义属性的获取和设置,如果设置为 Private 则需要这样来获取与赋值
Public Property Get top  ' 获取
top = int_Top
End Property

Public Property Let top(strVar)  ' 设置
int_Top = strVar
End Property

Public Property Get bottom
bottom = int_Bottom
End Property

Public Property Let bottom(strVar)
int_Bottom = strVar
End Property

Private Property Get stack(i)    ' 初学对什么时候用set有点乱...
SET stack = strStack(i)
End Property

Private Property Let stack(i,strVar)
SET strStack(i) = strVar
End Property

Private Property Get stacks
stacks = strStack
End Property

'类方法
Public Sub push(temp)
if top < MAX_STACK Then
stack(top) = temp
top = top + 1
Else
WScript.Echo "push(temp):stack gone max......"
End if
End Sub

Public Function pop()
if top > bottom Then
SET pop = stack(top-1)
top = top -1
Else
pop = 0
WScript.Echo "pop():stack gone bug......"
End if
End Function

Public Function Count()
Count = top - bottom
End Function
End Class
'----------------------------堆栈-------------------------------------
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: