Wednesday, 13 March 2013

Stack required for Evaluator (VB 6.0)

Stack required for Evaluator (VB 6.0)

Dim Stack(1000) As Variant
Dim vTop As Long
Const MaxValue = 1000

Sub push(value As Variant)
    If vTop >= MaxValue Then
        MsgBox "Stack OverFlow!", vbCritical, "Error!"
        Exit Sub
    Else
        vTop = vTop + 1
        Stack(vTop) = value
    End If
End Sub

Sub FlushStack()
    vTop = 0
End Sub

Function pop() As Variant
    If vTop > 0 Then
        pop = Stack(vTop)
        vTop = vTop - 1
    Else
        MsgBox "Stack Empty!", vbCritical, "Error!"
        Exit Function
    End If
End Function

Function IsEmpty() As Boolean
    If vTop = 0 Then
        IsEmpty = True
    Else
        IsEmpty = False
    End If
End Function

Function IsFilled() As Boolean
    If vTop = MaxValue Then
        IsFilled = True
    Else
        IsFilled = False
    End If
End Function

No comments:

Post a Comment