Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
41
Task/Stack/Run-BASIC/stack.basic
Normal file
41
Task/Stack/Run-BASIC/stack.basic
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
dim stack$(10) ' stack of ten
|
||||
global stack$
|
||||
global stackEnd
|
||||
|
||||
for i = 1 to 5 ' push 5 values to the stack
|
||||
a$ = push$(chr$(i + 64))
|
||||
print "Pushed ";chr$(i + 64);" stack has ";stackEnd
|
||||
next i
|
||||
|
||||
print "Pop Value:";pop$();" stack has ";stackEnd ' pop last in
|
||||
print "Pop Value:";pop$();" stack has ";stackEnd ' pop last in
|
||||
|
||||
e$ = mt$() ' MT the stack
|
||||
print "Empty stack. stack has ";stackEnd
|
||||
|
||||
' ------ PUSH the stack
|
||||
FUNCTION push$(val$)
|
||||
stackEnd = stackEnd + 1 ' if more than 10 then lose the oldest
|
||||
if stackEnd > 10 then
|
||||
for i = 0 to 9
|
||||
stack$(i) = stack$(i+1)
|
||||
next i
|
||||
stackEnd = 10
|
||||
end if
|
||||
stack$(stackEnd) = val$
|
||||
END FUNCTION
|
||||
|
||||
' ------ POP the stack -----
|
||||
FUNCTION pop$()
|
||||
if stackEnd = 0 then
|
||||
pop$ = "Stack is MT"
|
||||
else
|
||||
pop$ = stack$(stackEnd) ' pop last in
|
||||
stackEnd = max(stackEnd - 1,0)
|
||||
end if
|
||||
END FUNCTION
|
||||
|
||||
' ------ MT the stack ------
|
||||
FUNCTION mt$()
|
||||
stackEnd = 0
|
||||
END FUNCTION
|
||||
Loading…
Add table
Add a link
Reference in a new issue