com >> How to display a binary tree?

by WB » Tue, 04 Oct 2005 15:45:53 GMT

does anyone know of an activeX control to display a binary tree? like a
Treeview control, but where each node can have just a left and right child
nodes.

Or, alternatively, some code to do it? Each node just has a # in it, from 0
to 254. It's a BSP (Binary Space Partition) tree that stores the objects
that the user may be able to see in a game at any given time. I've already
written the code that stores the tree in a user defined data structure, but
have had problems trying to display it on the screen.

Thanks in advance.
baldwinwh (at) netscape (dot) net


Similar Threads

1. How to display a binary tree?

does anyone know of an activeX control to display a binary tree?  like a
Treeview control, but where each node can have just a left and right child
nodes.

Or, alternatively, some code to do it?  Each node just has a # in it, from 0
to 254.  It's a BSP (Binary Space Partition) tree that stores the objects
that the user may be able to see in a game at any given time.  I've already
written the code that stores the tree in a user defined data structure, but
have had problems trying to display it on the screen.

Thanks in advance.
baldwinwh (at) netscape (dot) net

2. Use SyncLock or Monitor on a binary tree - VB.Net

3. Binary Search Tree - CompareTo Error

Hello,

In a Binary Search Tree I get the error : Object must be of type String

if I run the form only with the   "Dim bstLidnummer As New BinarySearchTree"
it works fine.

Thanks for any help on this,

Benny

 My BST-code lookes lokes this :
**************************************************
Class BST
**************************************************
Public Class BinarySearchTree
   Private Class TreeNode
      Private mData As IComparable
      Private mLeftNode As TreeNode
      Private mRightNode As TreeNode

      Public Sub New(ByVal data As IComparable)
         Me.mData = data
      End Sub

      Public ReadOnly Property Data() As IComparable
         Get
            Return Me.mData
         End Get
      End Property

      Public Property LeftNode() As TreeNode
         Get
            Return Me.mLeftNode
         End Get
         Set(ByVal value As TreeNode)
            Me.mLeftNode = value
         End Set
      End Property

      Public Property RightNode() As TreeNode
         Get
            Return Me.mRightNode
         End Get
         Set(ByVal value As TreeNode)
            Me.mRightNode = value
         End Set
      End Property

      Public Sub Add(ByVal data As IComparable)
         If data.CompareTo(Me.mData) <= 0 Then
            If Me.mLeftNode Is Nothing Then
               Me.mLeftNode = New TreeNode(data)
            Else
               Me.mLeftNode.Add(data)
            End If
         Else
            If Me.mRightNode Is Nothing Then
               Me.mRightNode = New TreeNode(data)
            Else
               Me.mRightNode.Add(data)
            End If
         End If
      End Sub
   End Class

   Private mRoot As TreeNode

   Public Sub Add(ByVal data As IComparable)
      If mRoot Is Nothing Then
         mRoot = New TreeNode(data)
      Else
         mRoot.Add(data)
      End If
   End Sub

   Public Function Search(ByVal data As IComparable) As Object
      Return Me.Search(data, Me.mRoot)
   End Function

   Private Function Search(ByVal data As IComparable, ByVal node As
TreeNode) As Object

      If node Is Nothing Then
         Return Nothing
      Else
         Dim result As Integer = data.CompareTo(node.Data)  '****** this is
the error I get on this line :Object must be of type String.

         If result = 0 Then
            Return node.Data
         ElseIf result < 0 Then
            Return Me.Search(data, node.LeftNode)
         Else
            Return Me.Search(data, node.RightNode)
         End If
      End If

   End Function
End Class
*****************************
The class Person
*****************************
Public Class Persoon
   Inherits BusinessObject
   Implements IComparable

   Private mVnaam As String
   Private mAnaam As String

   Public Sub New(ByVal Vnaam As String, ByVal Anaam As String)
      Me.mVnaam = Vnaam
      Me.mAnaam = Anaam
   End Sub

   Public Property Vnaam() As String
      Get
         Return Me.mVnaam
      End Get
      Set(ByVal value As String)
         mVnaam = value
      End Set
   End Property

   Public Property Anaam() As String
      Get
         Return Me.mAnaam
      End Get
      Set(ByVal value As String)
         Me.mAnaam = value
      End Set
   End Property

   Public Overrides Function IsValid() As Boolean
      If Me.isValidVnaam() And Me.isValidAnaam() Then
         Return True
      Else
         Return False
      End If
   End Function

   Private Function isValidVnaam() As Boolean
      If Me.Vnaam.Trim.Length > 0 Then
         Return True
      Else
         Return False
      End If
   End Function

   Private Function isValidAnaam() As Boolean
      If Me.Anaam.Trim.Length > 0 Then
         Return True
      Else
         Return False
      End If
   End Function

   Public Overloads Function CompareTo(ByVal obj As Object) As Integer
Implements System.IComparable.CompareTo
      Return Me.mVnaam.CompareTo(CType(obj, Persoon).Vnaam)
   End Function
End Class
**********************************
The Form :
**********************************
Public Class frmBinarySearchTree

   Private Sub btnExecute_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnExecute.Click
      Dim bstLedenLijst As New BinarySearchTree
      Dim bstLidnummer As New BinarySearchTree
      Dim txtOutput As String = ""

      bstLidnummer.Add("5")
      bstLidnummer.Add("2")
      bstLidnummer.Add("1")
      bstLidnummer.Add("4")
      bstLidnummer.Add("3")
      txtOutput = bstLidnummer.Search("3") & vbCrLf

      bstLedenLijst.Add(New Persoon("Nicole", "Kidman"))
      bstLedenLijst.Add(New Persoon("Jamie-Lee", "Curtis"))
      bstLedenLijst.Add(New Persoon("Demi", "Moore"))
      bstLedenLijst.Add(New Persoon("Julia", "Roberts"))
      bstLedenLijst.Add(New Persoon("Andie", "MacDowell"))

      txtOutput &= bstLedenLijst.Search("Demi") ' & vbCrLf

      Me.txtOutput.Text = txtOutput

   End Sub

   Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnExit.Click
      Application.Exit()
   End Sub

End Class



4. vbscript binary tree - help needed

5. displaying pics when click on a tree node

6. VBA - Tree view control data is not displayed (TreeView 6.0, Excel 2000, Windows 2000)

7. VBA - Tree view control data is displayed blank

Hello,

I have been using Tree View control on Excel 2000 VBA under Windows
2000. The tree is succesfully populated with data and displayed as
expected. However, in a couple of additional tests (same SW
configuration, different PCs) the tree view did not display any of the
data: It appears blank to the user. The nodes in the tree are loaded
with data however, the problem is that none of them are visualized. I
have found some other users reported the same problem; the alternatives
I have tested did not lead to any results (adding a delay via timer
while populating the tree, populating the tree view control in Load
event of the form).

Is there any known incompatiblity in Tree View or any dependency of
this control to be aware of (e.g. verify that a particular .dll exists
in the target PC, etc)? If anyone can kindly provide references to
solve this it would be greatly appreciated.

BR,
SK

8. display this coding into tree view - Visual Basic/VB