User:Eriksiers/Linked List: Difference between revisions
Fixed old lang -> syntaxhighlight error
(created) |
(Fixed old lang -> syntaxhighlight error) |
||
(2 intermediate revisions by the same user not shown) | |||
Line 1:
This is a [[linked list]] class for [[:Category:Visual Basic|Visual Basic]] & [[:Category:VBA|VBA]]. It should work at least as far back as VB4.
<
Private Type Node
data As Variant
End Type
Line 58:
listEmpty = False
curNode = 0
nodes(0).
nodes(0).
Else
Dim tmp As Variant
tmp = UBound(nodes) + 1
ReDim Preserve nodes(tmp)
'this If block splices the new node into the list
If Before = where Then
nodes(nodes(curNode).
nodes(tmp).
nodes(tmp).
nodes(curNode).
Else
nodes(nodes(curNode).
nodes(tmp).
nodes(tmp).
nodes(curNode).
End If
curNode = tmp
Line 89:
If UBound(nodes) > 0 Then
'patch the surrounding elements together
nodes(nodes(curNode).
nodes(nodes(curNode).
'select the appropriate
curNode = nodes(curNode).
'finally, the actual delete
ReDim Preserve nodes(UBound(nodes) - 1)
Line 103:
Else
'patch the surrounding elements together
nodes(nodes(curNode).
nodes(nodes(curNode).
'swap with node at end of list
Dim tmp As Node
Line 111:
nodes(curNode) = tmp
'patch the list
nodes(nodes(curNode).
nodes(nodes(curNode).
'select the appropriate
If UBound(nodes) <> nodes(UBound(nodes)).
'finally, the actual delete
ReDim Preserve nodes(UBound(nodes) - 1)
Line 123:
Public Function nextnode() As Boolean
End Function
Public Function prevNode() As Boolean
▲End Function</lang>
==Simplified==
Line 146 ⟶ 136:
With minor modifications, this could conceivably work under QBasic (though obviously not as a class).
<
Public Enum BeforeOrAfter
Before = 0
Line 243 ⟶ 233:
End If
prevNode = True
End Function</
|