Skip to main content

Inorder traversal of binary tree with recursion in

Vb program for Inorder traversal of binary tree with recursion. Here problem description and explanation.

' Include namespace system
Imports System 
' Program for
'  inorder tree traversal of a Binary Tree
'  using recursion

'  Binary Tree Node
Public Class TreeNode 
    Public  data As Integer
    Public  left As TreeNode
    Public  right As TreeNode
    Public Sub New(ByVal data As Integer)
        '  Set node value = data
        Me.left = Nothing
        Me.right = Nothing
    End Sub

End Class
public Class BinaryTree 
    Public  root As TreeNode
    Public Sub New()
        '  Set initial tree root
        Me.root = Nothing
    End Sub
    '  Display Inorder view of binary tree
    Public Sub inorder(ByVal node As TreeNode)
        if (node IsNot Nothing) Then 
            '  Visit left subtree
            ' Print node value
            Console.Write("  " +
            '  Visit right subtree
        End If

    End Sub
    Public Shared Sub Main(ByVal args As String())
        '  Create new tree
        Dim tree As BinaryTree = New BinaryTree()
        '    Make A Binary Tree
        '    ----------------
        '        15
        '       /  \
        '      24   54
        '     /    /  \
        '    35   62   13
        '  Add tree TreeNode
        tree.root = New TreeNode(15)
        tree.root.left = New TreeNode(24)
        tree.root.right = New TreeNode(54)
        tree.root.right.right = New TreeNode(13)
        tree.root.right.left = New TreeNode(62)
        tree.root.left.left = New TreeNode(35)
        '  Display Tree Node
    End Sub

End Class


  35  24  15  62  54  13


Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment