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

时间:2022-07-26
本文章向大家介绍vbs - 一个简单的栈 -- 只能存储类对象,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
'----------------------------堆栈-------------------------------------
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
'----------------------------堆栈-------------------------------------