Skip to content

Commit

Permalink
ADDED BINARY TREE ...
Browse files Browse the repository at this point in the history
  • Loading branch information
spydaz committed Jun 2, 2018
1 parent 9dd65a7 commit a641a1b
Showing 1 changed file with 100 additions and 0 deletions.
100 changes: 100 additions & 0 deletions ClassTrie/Trie.vb
Original file line number Diff line number Diff line change
Expand Up @@ -625,3 +625,103 @@ Public Module Extended
End Function

End Module
''' <summary>
''' All nodes in a binary Tree have Left and Right nodes Nodes are added to the end of the
''' tree organized then the tree can be reorganized the rules are such that the lowest
''' numbers are always on the left and the highest numbers are on the right
''' </summary>
Public Class BinaryTree

Public Sub New(ByVal Data As Integer)
Me.Data = Data
End Sub

Public Property Prnt As String
Get
Return PRN

End Get
Set(value As String)
PRN = value
End Set
End Property

Public Function Contains(ByRef ExistingData As Integer) As Boolean
Return If(ExistingData = Me.Data, True, If(ExistingData < Data, If(Left Is Nothing, False, Left.Contains(ExistingData)), If(Right Is Nothing, False, Right.Contains(ExistingData))))
End Function

''' <summary>
''' Inserts new data into tree and adds node in appropriate place
''' </summary>
''' <param name="NewData"></param>
Public Sub insert(ByVal NewData As Integer)
If NewData <= Data Then
If Left IsNot Nothing Then
Left = New BinaryTree(NewData)
Else
Left.insert(NewData)
End If
Else
If Right IsNot Nothing Then
Right = New BinaryTree(NewData)
Else
Right.insert(NewData)
End If
End If

End Sub

''' <summary>
''' Prints in order ABC Left then Root then Right B=Root A=Left C=Right
''' </summary>
Public Sub PrintInOrder()
If Left IsNot Nothing Then
Left.PrintInOrder()
End If

Prnt &= "Node :" & Me.Data & vbNewLine
If Right IsNot Nothing Then
Right.PrintInOrder()
End If

End Sub

''' <summary>
''' Prints in order ACB Left then Right Then Root B=Root A=Left C=Right
''' </summary>
Public Sub PrintPostOrder()
'Left Nodes
If Left IsNot Nothing Then
Left.PrintInOrder()
End If
'Right nodes
If Right IsNot Nothing Then
Right.PrintInOrder()
End If

'Root
Prnt &= "Node :" & Me.Data & vbNewLine
End Sub

''' <summary>
''' Prints in order BAC Root then left then right B=Root A=Left C=Right
''' </summary>
Public Sub PrintPreOrder()
'Root
Prnt &= "Node :" & Me.Data & vbNewLine
'Right nodes
If Right IsNot Nothing Then
Right.PrintInOrder()
End If
'Left Nodes
If Left IsNot Nothing Then
Left.PrintInOrder()
End If
End Sub

Private PRN As String = ""

Public Data As Integer
Public Left As BinaryTree
Public Right As BinaryTree
End Class

0 comments on commit a641a1b

Please sign in to comment.