Gentil_poussin | Bonjour à tous (ou bonsoir c'est selon)
J'ai créé une classe Tree qui correspond à un objet de type arbre binaire (un élément data et deux pointeurs Up et down vers des arbres)
JE poste le code de la classe
Code :
- Private varData As Double
- Private varUp As tree
- Private varDown As tree
- Public Property Let data(ByVal vdata As Double)
- varData = vdata
- End Property
- Public Property Get data() As Double
- data = varData
- End Property
- Public Property Set up(ByVal vUp As tree)
- Set varUp = vUp
- End Property
- Public Property Get up() As tree
- Set up = varUp
- End Property
- Public Property Set down(ByVal vdown As tree)
- Set varDown = vdown
- End Property
- Public Property Get down() As tree
- Set down = varDown
- End Property
- Public Function isempty(tree As tree) As Boolean
- If tree Is Nothing Then
- isempty = True
- Else
- isempty = False
- End If
- End Function
- Public Function upchild(tree As tree) As tree
- If isempty(tree) Then
- Set upchild = Nothing
- Else
- Set upchild = tree.up
- End If
- End Function
- Public Function downchild(tree As tree) As tree
- If isempty(tree) Then
- Set downchild = Nothing
- Else
- Set downchild = tree.down
- End If
- End Function
- Public Function isLeave(tree As tree) As Boolean
- If isempty(tree) Then
- isLeave = False
- ElseIf isempty(upchild(tree)) And isempty(downchild(tree)) Then
- isLeave = True
- Else
- isLeave = False
- End If
- End Function
- Public Function isInternalNode(tree As tree) As Boolean
- isInternalNode = Not (isLeave(tree))
- End Function
- Public Function height(tree As tree) As Integer
- If isempty(tree) Then
- height = 0
- Else
- height = 1 + Max(height(upchild(tree)), height(downchild(tree)))
- End
- End Function
- Public Function NumberNode(tree As tree) As Integer
- If isempty(tree) Then
- NumberNode = 0
- Else
- NumberNode = 1 + NumberNode(upchild(tree)) + NumberNode(downchild(tree))
- End If
- End Function
- Public Function NumberLeave(tree As tree) As Integer
- If isempty(tree) Then
- NumberLeave = 0
- ElseIf (isLeave(tree)) Then
- NumberLeave = 1
- Else
- NumberLeave = NumberLeave(upchild(tree)) + NumberLeave(downchild(tree))
- End If
- End Function
- Public Function NumberInternalNode(tree As tree) As Integer
- If isempty(tree) Then
- NumberInternalNode = 0
- ElseIf (isLeave(tree)) Then
- NumberInternalNode = 0
- Else
- NumberInternalNode = 1 + NumberInternalNode(upchild(tree)) + NumberInternalNode(downchild(tree))
- End If
- End Function
- Public Sub TraiterRacine(tree As tree)
- End Sub
- Public Sub DFS(tree As tree, Type_Exploration As Integer)
- If Not isempty(tree) Then
- If Type_Exploration = 1 Then tree.TraiterRacine
- tree.DFS upchild(tree), Type_Exploration
- If Type_Exploration = 2 Then tree.TraiterRacine
- tree.DFS downchild(tree), Type_Exploration
- If Type_Exploration = 3 Then tree.TraiterRacine
- End If
-
- Public Sub DFS_prefix(tree As tree)
- tree.DFS tree, 1
- End Sub
- Public Sub DFS_infix(tree As tree)
- tree.DFS tree, 2
- End Sub
- Public Sub DFS_postfix(tree As tree)
- tree.DFS tree, 3
- End Sub
- Public Function create(data As Double, upchild As tree, downchild As tree) As tree
- create.data = data
- Set create.up = upchild
- Set create.down = downchild
- End Function
- Public Sub AddNode(src As tree, data As Double)
- If src Is Nothing Then
- Set src = create(data, Nothing, Nothing)
- ElseIf isempty(src.up) Then
- Set src.up = create(data, Nothing, Nothing)
- ElseIf isempty(src.down) Then
- Set src.down = create(data, Nothing, Nothing)
- Else
- src.AddNode src.up, data
- End If
- End Sub
- Public Sub InsertSearchTree(src As tree, data As Double)
- If isempty(src) Then
- Set src = create(data, Nothing, Nothing)
- Else
- If data < src.data Then
- InsertSearchTree src.up, data
- Else
- InsertSearchTree src.down, data
- End If
- End If
- End Sub
|
1/ Si vous voyez une erreur qqpart ou des améliorations notoires, n'hésitez pas à me le dire ... ;-)
2/ LE problème est le suivant:
Dans mon module je fais un test pour voir si tout fonctionne bien et en particulier la procédure addnode
=>
Code :
- Sub test()
- Set temp = New tree
- Dim data As Double
- data = 3
- temp.AddNode temp, data
- End Sub
|
A la ligne temp.addnode.... je recois lors du débug un msg box run time error 13: type mismatch....
La question...: quel saint dois je prier pour trouver la solution...?????
Merci d'avance et a +
GP Message édité par Gentil_poussin le 29-08-2006 à 14:27:53
|