Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
37
Task/Stack/VBA/stack-1.vba
Normal file
37
Task/Stack/VBA/stack-1.vba
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
'Simple Stack class
|
||||
|
||||
'uses a dynamic array of Variants to stack the values
|
||||
'has read-only property "Size"
|
||||
'and methods "Push", "Pop", "IsEmpty"
|
||||
|
||||
Private myStack()
|
||||
Private myStackHeight As Integer
|
||||
|
||||
'method Push
|
||||
Public Function Push(aValue)
|
||||
'increase stack height
|
||||
myStackHeight = myStackHeight + 1
|
||||
ReDim Preserve myStack(myStackHeight)
|
||||
myStack(myStackHeight) = aValue
|
||||
End Function
|
||||
|
||||
'method Pop
|
||||
Public Function Pop()
|
||||
'check for nonempty stack
|
||||
If myStackHeight > 0 Then
|
||||
Pop = myStack(myStackHeight)
|
||||
myStackHeight = myStackHeight - 1
|
||||
Else
|
||||
MsgBox "Pop: stack is empty!"
|
||||
End If
|
||||
End Function
|
||||
|
||||
'method IsEmpty
|
||||
Public Function IsEmpty() As Boolean
|
||||
IsEmpty = (myStackHeight = 0)
|
||||
End Function
|
||||
|
||||
'property Size
|
||||
Property Get Size() As Integer
|
||||
Size = myStackHeight
|
||||
End Property
|
||||
Loading…
Add table
Add a link
Reference in a new issue