OpenNTF.org - Simple Stack Class in LotusScr
My Links (Not logged in)
Code Bin Search
 
Hosted by Prominic.NET
Rate This Code
5 - brilliant stuff
4 - very nice
3 - average
2 - needs work
1 - bad
   OpenNTF Code Bin
Edit Document Code By Date > Code Document
About This Code
Brief Description:
Simple Stack Class in LotusScript 
Rating:
Not Rated Yet 
Contributor:
Andre Guirard 
Category:
Lotus Formula 
Type:
List functions 
Document Release:
1.0 
Notes Version:
R4.x, R6.x, R8.x, R5.x, R7.x 
Last Modified:
02 Apr 2009 
OpenNTF Disclaimer

All of the program code and information presented in the OpenNTF.org Code Bin are provided "as-is", and should be used at your own risk. OpenNTF.org make no express or implied warranty about anything in the Code Bin, and OpenNTF.org will not be responsible or liable for any damage caused by the use or misuse of anything from this site. OpenNTF.org makes no guarantees about anything. Please thoroughly test all of the knowledge and code you find here before you attempt to use them in your production environment.

Code / Description
A simple class to implement the classic "Stack" data structure in LotusScript. The data may be of any type. It's pretty quick, and I've tested it to 300,000 small elements; probably it'll work with many more.


Private Class StackNode
Public value As Variant
Public next As StackNode

Sub New(datum)
If Isobject(datum) Then Set value = datum Else value = datum
End Sub
End Class

Class Stack
m_top As StackNode

Sub Push(x)
Dim sn As New StackNode(x)
Set sn.next = m_top
Set m_top = sn
End Sub

Function Pop()
If Not (m_top Is Nothing) Then
If Isobject(m_top.value) Then
Set Pop = m_top.value
Else
Pop = m_top.value
End If
Set m_top = m_top.next
End If
End Function

Function Peek()
If Not (m_top Is Nothing) Then
If Isobject(m_top.value) Then
Set Peek = m_top.value
Else
Peek = m_top.value
End If
End If
End Function

Public Property Get IsEmpty() As Boolean
Me.IsEmpty = (m_top Is Nothing)
End Property
End Class

Usage / Example
Sub Click(Source As Button)
Dim stak As New Stack

stak.Push "eek"
stak.Push "hey"
stak.Push "too late"
Print debugstr(stak.Pop) ' prints "too late" (note: debugstr function sold separately)
Print debugstr(stak.Pop) ' prints "hey"
Print debugstr(stak.Peek) ' prints "eek"
stak.Push "why?"
stak.Push "eh?"
Dim ndt As New notesdatetime(Today)
stak.Push ndt
stak.push 7
Do Until stak.isempty()
Print debugstr(stak.Pop()) ' prints 7, NOTESDATETIME, "eh?", "why?", "eek"
Loop
Print debugstr(stak.Pop()) ' prints EMPTY
End Sub
 Comments

No documents found

 Add your comment!