• Welcome to Theos PowerBasic Museum 2017.

String-Stack - Include

Started by Theo Gottwald, January 10, 2011, 09:24:47 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Theo Gottwald

Again we have an Stack. This time you can not only add numbers, but add Strings of any lenght.
PUSH them on the Stack, and POP them off the Stack.
Just include this Library and it will work.

How do you use this?
Just declare a String, for Example:

QuoteGLOBAL MyStri$
Global MyElem$

Now you are ready to go. Put something on your String-Stack like this:

MyElem$="Here is the first Element!")
D_AddTos_A(MyStri$,MyElem$)

' and POP it off

MyElem$=D_GetRemTOS_A(MyStri$)

'You can also just take it off without having it removed:

D_GetTOS_A(MyStri$)

' Using

x&=D_GetAnz_A(MyStri$)

You'll get the number of Elements on your String-Stack.

Note: that AddTOS (Add to Top-Of-Stack) currently wants the String BYREF because thats faster. If you want to Add like that:

D_AddTos_A(MyStri$,"Hallo")
you need to change it to "BYVAL".

Here is what you can do:

D_Init_Stack_A ' Clear the Stack
D_AddTos_A ' Add one Element
D_GetRemTOS_A ' POP one Element
D_GetTOS_A ' just get a Copy of the upper element
D_RemLast_A ' Remove the TopMost Element
D_GetAnz_A ' See how many Elements are on your Stack

As you can use it with any String, you can have an unlimited number of Stacks!