Om ni vill ha så bjuder jag på min dags förhöjare, detta räddade iallafall min dag. Skrev den på bussen på vägen hem efter att ha upptäkt ett behov av att ha en stack.
Vist är det kul att bli nöjd över så lite
Class cls_Stack
Dim oStore
Dim iStoreCount
Public Property Get count()
' Antalet poster i stacken
count = iStoreCount
End Property
Private Sub Initialize()
' Skapar en Dictionary
Set oStore = Server.CreateObject("Scripting.Dictionary")
End Sub
Private Sub Terminate()
' Terminerar Dictionary
oStore = Nothing
End Sub
Public Sub push(value)
' Lägger till överst i stacken
If iStoreCount=0 Then
Initialize()
End If
iStoreCount = iStoreCount + 1
oStore(iStoreCount) = value
End Sub
Public Function pop()
If iStoreCount<1 Then
pop = "#Error# Stack is empty!"
Exit Function
End If
pop = oStore(iStoreCount)
oStore.Remove(iStoreCount)
iStoreCount = iStoreCount -1
If iStoreCount < 1 Then
Terminate()
End If
End Function
End Class
Class cls_Stack
'
'
' Property:
' SizeOfStack ; Returns number of items in stack
' Methods:
' Push() ; Adds new value to stack
' Events:
' Pop ; Retrives value from stack
' Kill ; Kills and resets stack
'
Dim oStore
Dim iStoreCount
Public Property Get SizeOfStack()
If iStoreCount<1 Then
SizeOfStack = 0
Else
SizeOfStack = iStoreCount
End If
End Property
Private Sub Initialize()
Set oStore = Server.CreateObject("Scripting.Dictionary")
End Sub
Private Sub Terminate()
If oStore Is Nothing Then
Exit Sub
Else
iStoreCount = 0
Set oStore = Nothing
End IF
End Sub
Public Sub push(value)
If iStoreCount="" Then
Initialize()
End If
iStoreCount = iStoreCount + 1
oStore(iStoreCount) = value
End Sub
Public Sub Kill()
iStoreCount = ""
Terminate()
End Sub
Public Function pop()
If iStoreCount<1 Then
pop = "#Error# Stack is empty!"
Exit Function
End If
pop = oStore(iStoreCount)
oStore.Remove(iStoreCount)
iStoreCount = iStoreCount -1
If iStoreCount<1 Then
Terminate()
End If
End Function
End Class
Lite bättre
Krachar inte när man popar en tom stack mer än en gång