50 lines
1.2 KiB
Plaintext
50 lines
1.2 KiB
Plaintext
' FB 1.05.0 Win64
|
|
|
|
#Include "stack_rosetta.bi"
|
|
|
|
Type Dog
|
|
name As String
|
|
age As Integer
|
|
Declare Constructor
|
|
Declare Constructor(name_ As string, age_ As integer)
|
|
Declare Operator Cast() As String
|
|
end type
|
|
|
|
Constructor Dog '' default constructor
|
|
End Constructor
|
|
|
|
Constructor Dog(name_ As String, age_ As Integer)
|
|
name = name_
|
|
age = age_
|
|
End Constructor
|
|
|
|
Operator Dog.Cast() As String
|
|
Return "[" + name + ", " + Str(age) + "]"
|
|
End Operator
|
|
|
|
Declare_Stack(Dog) '' expand Stack type for Dog instances
|
|
|
|
Dim dogStack As Stack(Dog)
|
|
|
|
Var cerberus = Dog("Cerberus", 10)
|
|
Var rover = Dog("Rover", 3)
|
|
Var puppy = Dog("Puppy", 0)
|
|
With dogStack '' push these Dog instances onto the stack
|
|
.push(cerberus)
|
|
.push(rover)
|
|
.push(puppy)
|
|
End With
|
|
Print "Number of dogs on the stack :" ; dogStack.count
|
|
Print "Capacity of dog stack :" ; dogStack.capacity
|
|
Print "Top dog : "; dogStack.top
|
|
dogStack.pop()
|
|
Print "Top dog now : "; dogStack.top
|
|
Print "Number of dogs on the stack :" ; dogStack.count
|
|
dogStack.pop()
|
|
Print "Top dog now : "; dogStack.top
|
|
Print "Number of dogs on the stack :" ; dogStack.count
|
|
Print "Is stack empty now : "; dogStack.empty
|
|
Print
|
|
Print "Press any key to quit"
|
|
Sleep
|