I love stacks and strings
Here is a quad stack held inside a string. When you run out of stack space the string is automatically extended.
[code=thinbasic]
'==========================
'QUAD STACK USING A STRING:
'==========================
Dim As String s 'STACK
Dim As Long p=1 'STACK POINTER
'------------------
Sub push(q As Quad)
'==================
If p+8>Len(s) Then
s+=String$(8000,Chr$(0))
End If
Mid$(s,p)=MKQ$(q)
p+=8
End Sub
'---------------------
Function pop() As Quad
'=====================
If p<9 Then
MsgBox 0,"Stack empty!"
Exit Function
End If
p-=8
Function=CVQ(s, p)
End Function
push 1 : push 2 push 3
MsgBox 0,"POPS"+$CRLF+pop+$CRLF+pop+$CRLF+pop
pop 'ATTEMPT TO POP FROM AN EMPTY STACK
[/code]
Bookmarks