I have a problem. I wrote a "stack"-class, where you can push and pop strings. This works well, however I want to prevent the stack getting to big. So when the stack reaches the size 6, I want to cut off the lower half, but I don't want to loose the top half. How would I do that?
I tried it like this, but it cuts off the wrong half (see the sub "t_Stack.push"):
Code: Select all
as string __stack(any)
as long __stack_pointer
as long __real_ubound
declare sub push(topush as string)
declare function pop()as string
declare sub output()
sub t_Stack.push(topush as string)
if __stack_pointer>ubound(__stack) then redim preserve __stack(0 to ubound(__stack)+64)
if __real_ubound>6 then __real_ubound=3 '??
function t_Stack.pop()as string
if __stack_pointer<1 then return ""
for i as integer=0 to __real_ubound-1
if __stack_pointer-1=i then print ">";
print str(i)+": "+__stack(i)
dim as t_Stack test