数组实现栈,保存到模块中
Public Const MaxSize As Integer = 10 Public Type SeqStack Data(0 To MaxSize – 1) As Integer top As Integer End Type ‘栈的初始化 Public Sub initStack(st As SeqStack) st.top = -1 End Sub ‘压栈 Public Sub push(st As SeqStack, e As Integer) If st.top = MaxSize – 1 Then MsgBox (“栈已满”) Exit Sub Else st.top = st.top + 1 st.Data(st.top) = e End If End Sub ‘出栈 Public Function pop(st As SeqStack) As Integer If st.top = -1 Then MsgBox (“栈已满”) Exit Function Else pop = st.Data(st.top) st.top = st.top – 1 End If End Function |
2021年3月16日