RosettaCodeData/Task/Stack/Liberty-BASIC/stack.basic

39 lines
632 B
Plaintext

global stack$
stack$=""
randomize .51
for i = 1 to 10
if rnd(1)>0.5 then
print "pop => ";pop$()
else
j=j+1
s$ = chr$(j + 64)
print "push ";s$
call push s$
end if
next
print
print "Clean-up"
do
print "pop => ";pop$()
loop while not(empty())
print "Stack is empty"
end
'------------------------------------
sub push s$
stack$=s$+"|"+stack$ 'stack
end sub
function pop$()
if stack$="" then pop$="*EMPTY*": exit function
pop$=word$(stack$,1,"|")
stack$=mid$(stack$,instr(stack$,"|")+1)
end function
function empty()
empty =(stack$="")
end function