January 24, 2021, 12:52:40 PM
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email
?
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Home
Forum
Help
Search
Gallery
Login
Register
SyntaxBomb - Indie Coders
»
Languages & Coding
»
Blitz Code Archives
»
Algorithms
»
[bmx] Simple TStack by Galaxy613 [ 1+ years ago ]
« previous
next »
Print
Pages: [
1
]
Go Down
Author
Topic: [bmx] Simple TStack by Galaxy613 [ 1+ years ago ] (Read 675 times)
BlitzBot
Jr. Member
Posts: 1
[bmx] Simple TStack by Galaxy613 [ 1+ years ago ]
«
on:
June 29, 2017, 12:28:38 AM »
Title :
Simple TStack
Author :
Galaxy613
Posted :
1+ years ago
Description :
I just needed a simple way to adding objects to a list and then when I take one off the top, it goes down a level... then I remember stacks, and found out that BlitzMax doesn't have them! I think a few others have submitted their version of doing stacks, but this is how I did it...
Code :
Code: BlitzMax
Type
TStack
Field
Top:TStackElement
Field
Bottom:TStackElement
Field
Depth% =
0
Method
Pop:
Object
(
)
If
Top =
Null
Then
Return
Null
Local
tmp:TStackElement = Top
If
Top <> Bottom
Then
Top = Top.Parent
Else
Top =
Null
Bottom =
Null
EndIf
Depth:-
1
Return
Tmp.Data
End
Method
Method
Push
(
Data:
Object
)
Local
tmp:TStackElement =
New
TStackElement
tmp.data = data
tmp.parent = Top
Top = tmp
Depth:+
1
If
Bottom =
Null
Then
Bottom = tmp
End
Method
End
Type
Type
TStackElement
Field
Parent:TStackElement
Field
Data:
Object
End
Type
''' TStack Test
Global
testStack:TStack =
New
TStack
testStack.Push
"1"
Print
(
String
testStack.Top.data
)
+
" "
+
(
String
testStack.Bottom.data
)
testStack.Push
"2"
Print
(
String
testStack.Top.data
)
+
" "
+
(
String
testStack.Bottom.data
)
testStack.Push
"3"
Print
(
String
testStack.Top.data
)
+
" "
+
(
String
testStack.Bottom.data
)
Local
tmpStr$ =
String
testStack.Pop
(
)
Print
(
String
testStack.Top.data
)
+
" "
+
(
String
testStack.Bottom.data
)
+
" "
+tmpStr
tmpStr$ =
String
testStack.Pop
(
)
Print
(
String
testStack.Top.data
)
+
" "
+
(
String
testStack.Bottom.data
)
+
" "
+tmpStr
tmpStr$ =
String
testStack.Pop
(
)
Print tmpStr
tmpStr$ =
String
testStack.Pop
(
)
Comments :
none...
Logged
Print
Pages: [
1
]
Go Up
« previous
next »
SyntaxBomb - Indie Coders
»
Languages & Coding
»
Blitz Code Archives
»
Algorithms
»
[bmx] Simple TStack by Galaxy613 [ 1+ years ago ]
SimplePortal 2.3.6 © 2008-2014, SimplePortal