Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
49
Task/Stack/FreeBASIC/stack-2.basic
Normal file
49
Task/Stack/FreeBASIC/stack-2.basic
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
' 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue