高手请进,毕生碰到最难的树型链表(!!!)
本帖最后由 bcrun 于 2013-03-28 11:56:02 编辑 最近接了一个项目,保存数据时,要用到树型链表,无限层,
经过最新的收集资料,写了简单的链表,还有很多问题没有搞定
我的太至代码如下
和网上的差不多,唯有不同的时候,就是我的 pdata不是一个单纯的数字字符串,
而是一个多参数的集合体,如:Height,Width,X,Y之类的和数组变量
经我测试,自定义类型,它不能定义在类里作公共变量
我现在把它换成子类了(Pining),
'Node.cls
Option Explicit
Public pNext As Node
Public pPrev As Node
Public pdata As Pining
Private Sub Class_Initialize()
Set pdata = New Pining
Set pNext = Nothing
Set pPrev = Nothing
End Sub
Private Sub Class_Terminate()
Set pdata = Nothing
Set pNext = Nothing
Set pPrev = Nothing
End Sub
'Pining.cls
Public chengpin As ChengPinType
Private kongkuai(1 To 4) As KongType
'要有4个变量,连表时要计算用的,所以一定要数组才能循环计算
Private Sub Class_Initialize()
Set chengpin = New ChengPinType
Set kongkuai(1) = New KongType
Set kongkuai(2) = New KongType
Set kongkuai(3) = New KongType
Set kongkuai(4) = New KongType
End Sub
Public Property Get kong(ByVal Index As Long) As KongType
kong = kongkuai(Index)
End Property
Public Property Let kong(ByVal Index As Long, ByRef Item As KongType)
kongkuai(Index) = Item
End Property
'第一个节点
Set Top = New Node
Top.pdata.chengpin.chang = 33 ' 正常
Top.pdata.kong(2).Height=22 '这行就不行了
Public Property Get kong(ByVal Index As Long) As KongType
Set kong = kongkuai(Index)
End Property
Public Property Set kong(ByVal Index As Long, ByRef Item As KongType)
Set kongkuai(Index) = Item
End Property