Private priPack As tpLoopDelete_Pack
Private priCount As Long
Private priBound As Long
Private Sub Form_Load()
priCount = 1000000 '数量
priBound = 7 '间隔
priPack = LoopDelete_PackCearte(priCount) '初始化链表
End Sub
Private Sub Command1_Click()
Dim tMode As Boolean '方向
Dim tIndexA As Long
Dim tIndexB As Long
Dim tBound As Long
tBound = priBound - 1
For tIndexA = 0 To priCount
tMode = (tIndexA Mod 2)
For tIndexB = 0 To tBound
If tMode Then
LoopDelete_PackIndexNext priPack
Else
LoopDelete_PackIndexBack priPack
End If
Next
LoopDelete_DeleteCell priPack.ldpCells(), priPack.ldpIndex
LoopDelete_PackIndexNext priPack
Next
Text1.Text = priPack.ldpCells(priPack.ldpIndex).ldcValue
End Sub
modLoopDelete.bas文件
Type tpLoopDelete_Cell '元素
ldcValue As Long '值
ldcIndex_Sur As Long '来源指针
ldcIndex_Des As Long '目的指针
End Type
Type tpLoopDelete_Pack
ldpIndex As Long '指针
ldpCells() As tpLoopDelete_Cell '元素数组
End Type
Public Sub LoopDelete_PackIndexBack(ByRef pPack As tpLoopDelete_Pack)
'前跳
pPack.ldpIndex = pPack.ldpCells(pPack.ldpIndex).ldcIndex_Sur
End Sub
Public Sub LoopDelete_PackIndexNext(ByRef pPack As tpLoopDelete_Pack)
'后跳
pPack.ldpIndex = pPack.ldpCells(pPack.ldpIndex).ldcIndex_Des
End Sub
Public Function LoopDelete_PackCearte(ByVal pCount As Long) As tpLoopDelete_Pack
'创建数据包
Dim tOutPack As tpLoopDelete_Pack
With tOutPack
.ldpCells() = LoopDelete_CellsCearte(pCount)
.ldpIndex = 0
End With
LoopDelete_PackCearte = tOutPack
End Function
Public Sub LoopDelete_DeleteCell(ByRef pCells() As tpLoopDelete_Cell, ByVal pIndex As Long)
'删除元素
Dim tCellDesIndex As Long
Dim tCellSurIndex As Long
With pCells(pIndex)
tCellDesIndex = .ldcIndex_Des
tCellSurIndex = .ldcIndex_Sur
End With
With pCells(tCellSurIndex)
.ldcIndex_Des = tCellDesIndex
End With
With pCells(tCellDesIndex)
.ldcIndex_Sur = tCellSurIndex
End With
End Sub
Public Function LoopDelete_CellsCearte(ByVal pCount As Long) As tpLoopDelete_Cell()
'元素数组创建
Dim tOutCells() As tpLoopDelete_Cell
Dim tCells_Index As Long
Dim tCells_Length As Long
tCells_Length = pCount - 1
ReDim tOutCells(tCells_Length)
Dim tCells_Index_LoopStart As Long
Dim tCells_Index_LoopEnd As Long
With tOutCells(0)
.ldcIndex_Sur = tCells_Length
.ldcIndex_Des = 1
.ldcValue = 0
End With
With tOutCells(tCells_Length)
.ldcIndex_Sur = tCells_Length - 1
.ldcIndex_Des = 0
.ldcValue = tCells_Length
End With
For tCells_Index = tCells_Index_LoopStart To tCells_Index_LoopEnd
With tOutCells(tCells_Index)
.ldcIndex_Sur = tCells_Index - 1
.ldcIndex_Des = tCells_Index + 1
.ldcValue = tCells_Index
End With
Next