Karl Blessing
Programmer
I so far am trying to create a sort of binary tree where left is '0' and right is '1' and each node has a total
so for example
101110
is broken in the function, which is rescursive as
[tt]
1
|-0(1)
| |-1(1)
| |-1(1)
| |-1(1)
| |-0(1)
[/tt]
then when adding another string such as
101101
[tt]
1(2)
|-0(2)
| |-1(2)
| |-1(2)
| |-1(1)
| | |-0(1)
| |-0(1)
| |-1(1)
[/tt]
notice how I want it to total up how many is under a certain branch, this is all I Want to do I am trying to do it with a collection but its becomming rather nerve racking espically with all the mismatch, or doesnt support, etc
this is the code I am using as the Rescursive function
these are the definitions of the class modules as I have them now
treecol.cls
one.cls
zero.cls
bin.cls
it used to be just TreeCol, except I Couldnt reference them correctly, then eventually had ByRef errors, and so on, so I'd appreciate it if someone knows of a better method to make a Sort of Binary tree in the memory ( not through controls like TreeView) so That I Can traverse them in the same manner later, this is just a very small peice for a project.
Karl
kb244@kb244.com
Experienced in : C++(both VC++ and Borland),VB1(dos) thru VB6, Delphi 3 pro, HTML, Visual InterDev 6(ASP(WebProgramming/Vbscript)
so for example
101110
is broken in the function, which is rescursive as
[tt]
1
|-0(1)
| |-1(1)
| |-1(1)
| |-1(1)
| |-0(1)
[/tt]
then when adding another string such as
101101
[tt]
1(2)
|-0(2)
| |-1(2)
| |-1(2)
| |-1(1)
| | |-0(1)
| |-0(1)
| |-1(1)
[/tt]
notice how I want it to total up how many is under a certain branch, this is all I Want to do I am trying to do it with a collection but its becomming rather nerve racking espically with all the mismatch, or doesnt support, etc
this is the code I am using as the Rescursive function
Code:
Public Function GetBinR(ByVal Binstring As String, Optional BinStart As Integer = 1, Optional TNode, Optional ByVal path As Integer = 2) As Long
Dim TmpCol As TreeCol 'Marker holder
Dim TC As Bin
Dim thepath As Integer
Dim TmpT As New Bin
If path = 2 Then
Set TmpCol = TreeC
ElseIf path = 1 Then
Set TmpCol = TNode.One
ElseIf path = 0 Then
Set TmpCol = TNode.Zero
End If
If BinStart <= Len(Binstring) Then
If Left(Mid(Binstring, BinStart), 1) = "1" Then
thepath = 1
Else
thepath = 0
End If
If path = 2 Then
If thepath = 1 Then
If TmpCol.One Is Nothing Then
Set TC = TmpCol.One
TmpCol.One.Add TmpT
Else
Set TmpT = TmpCol.One
End If
Else
If TmpCol.Zero Is Nothing Then
TmpCol.Zero.Add TmpT
Else
Set TmpT = TmpCol.Zero
End If
End If
Else
If TmpCol.Item(Left(Binstring, BinStart)) Is Nothing Then
TmpCol.Add (TmpT)
Else
Set TmpT = TmpCol.Item(Left(Binstring, BinStart))
End If
End If
TmpT.name = Left(Binstring, BinStart)
TmpT.Total = TmpT.Total + GetBinR(Binstring, BinStart + 1, TmpT, thepath)
End If
GetBinR = 1
End Function
these are the definitions of the class modules as I have them now
treecol.cls
Code:
Public One As New Collection
Public Zero As New Collection
one.cls
Code:
Dim Bin As New Collection
zero.cls
Code:
Dim Bin As New Collection
bin.cls
Code:
Public Total As Long
Public name As String
Public Zero As New Zero
Public One As New One
it used to be just TreeCol, except I Couldnt reference them correctly, then eventually had ByRef errors, and so on, so I'd appreciate it if someone knows of a better method to make a Sort of Binary tree in the memory ( not through controls like TreeView) so That I Can traverse them in the same manner later, this is just a very small peice for a project.
Karl
kb244@kb244.com
Experienced in : C++(both VC++ and Borland),VB1(dos) thru VB6, Delphi 3 pro, HTML, Visual InterDev 6(ASP(WebProgramming/Vbscript)