📄 clist.cls
字号:
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "CList"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
' Fix. 21.3
' Class CList
Option Explicit
Private mFirstNode As CListNode ' refers to first node in list
Private mLastNode As CListNode ' refers to last node in list
' determine if the list is empty
Public Function IsEmpty() As Boolean
IsEmpty = IIf(mFirstNode Is Nothing, True, False)
End Function
' insert an element at the beginning of the list
Public Sub InsertAtFront(insertItem As Variant)
Dim tempNode As CListNode
If IsEmpty() Then
Set mFirstNode = New CListNode
Set mLastNode = mFirstNode
Else
Set tempNode = mFirstNode
Set mFirstNode = New CListNode
mFirstNode.NextNode = tempNode
End If
mFirstNode.Data = insertItem
End Sub
' insert an element at the end of the list
Public Sub InsertAtBack(insertItem As Variant)
Dim tempNode As CListNode
If IsEmpty() Then
Set mLastNode = New CListNode
Set mFirstNode = mLastNode
Else
Set tempNode = mLastNode
Set mLastNode = New CListNode
tempNode.NextNode = mLastNode
End If
mLastNode.Data = insertItem
End Sub
' remove an element from the beginning of the list
Public Function RemoveFromFront()
Dim removeItem As Variant
If IsEmpty() Then
Call MsgBox("List is empty")
RemoveFromFront = Null
Exit Function
End If
removeItem = mFirstNode.Data
If mFirstNode Is mLastNode Then
Set mFirstNode = Nothing
Set mLastNode = Nothing
Else
Set mFirstNode = mFirstNode.NextNode
End If
RemoveFromFront = removeItem
End Function
' remove an element from the end of the list
Public Function RemoveFromBack()
Dim removeItem As Variant
Dim current As CListNode
If IsEmpty() Then
Call MsgBox("List is empty")
RemoveFromBack = Null
Exit Function
End If
removeItem = mLastNode.Data
If mFirstNode Is mLastNode Then
Set mFirstNode = Nothing
Set mLastNode = Nothing
Else
Set current = mFirstNode
While Not current.NextNode Is mLastNode
Set current = current.NextNode
Wend
Set mLastNode = current
current.NextNode = Nothing
End If
RemoveFromBack = removeItem
End Function
Public Property Get Iterator() As Variant
Dim iter As CListIterator
Set iter = New CListIterator
iter.StartNode = mFirstNode
Set Iterator = iter
End Property
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -