Skip to content

Instantly share code, notes, and snippets.

@kevinah95
Last active April 16, 2019 18:34
Show Gist options
  • Save kevinah95/7717e312bf7bfcf0b903930fc7ff4cb6 to your computer and use it in GitHub Desktop.
Save kevinah95/7717e312bf7bfcf0b903930fc7ff4cb6 to your computer and use it in GitHub Desktop.
Module Module1
Class Node
Public Key As Integer
Public Left, Right As Node
Sub New(Item As Integer)
Key = Item
Left = Nothing
Right = Nothing
End Sub
End Class
Class BinaryTree
Public Root As Node
Sub New()
Root = Nothing
End Sub
Sub PrintPreorder(Node As Node)
If Node Is Nothing Then
Return
End If
Console.WriteLine(Node.Key)
PrintPreorder(Node.Left)
PrintPreorder(Node.Right)
End Sub
Sub PrintInorder(Node As Node)
If Node Is Nothing Then
Return
End If
PrintInorder(Node.Left)
Console.WriteLine(Node.Key)
PrintInorder(Node.Right)
End Sub
Sub PrintPostOrder(Node As Node)
If Node Is Nothing Then
Return
End If
PrintPostOrder(Node.Left)
PrintPostOrder(Node.Right)
Console.WriteLine(Node.Key)
End Sub
Sub PrintPreorder()
PrintPreorder(Root)
End Sub
Sub PrintInorder()
PrintInorder(Root)
End Sub
Sub PrintPostOrder()
PrintPostOrder(Root)
End Sub
End Class
Sub Main()
Dim Tree As BinaryTree = New BinaryTree()
Tree.Root = New Node(1)
Tree.Root.Left = New Node(2)
Tree.Root.Right = New Node(3)
Tree.Root.Left.Left = New Node(4)
Tree.Root.Left.Right = New Node(5)
Tree.PrintPreorder()
Console.WriteLine("------Inorder-------")
Tree.PrintInorder()
Console.WriteLine("------Postorder-------")
Tree.PrintPostOrder()
Console.ReadLine()
End Sub
End Module
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment