RosettaCodeData/Task/Stack/Yabasic/stack.basic

41 lines
545 B
Plaintext

limit = 1000
dim stack(limit)
top = 0
sub push(n)
if top < limit then
top = top + 1 : stack(top) = n
else
print "stack full - ";
end if
end sub
sub pop()
if top then
top = top - 1 : return stack(top + 1)
else
print "stack empty - ";
end if
end sub
sub empty()
return not top
end sub
// ======== test ========
for n = 3 to 5
print "Push ", n : push(n)
next
print "Pop ", pop()
print "Push ", 6 : push(6)
while(not empty())
print "Pop ", pop()
wend
print "Pop ", pop()