Click here to Skip to main content
13,147,591 members (35,113 online)
Click here to Skip to main content
Add your own
alternative version

Stats

20.1K views
6 bookmarked
Posted 24 Apr 2006

Another Simple VB.NET Binary Tree

, 24 Apr 2006
Rate this:
Please Sign up or sign in to vote.
A simple binary tree with type constraints and a base class.

Introduction

This is a simple binary tree class that I wrote while writing a PDA program. It should work on any platform supporting the .NET Framework, and should be simple to port to any other .NET language. To use it, simply have your classes inherit from BinaryBase and then you can add your class to the tree. Be sure to only use one type of object per tree, or it will throw an exception.

For example:

Public Class MyClass Inherits BinaryBase

    Private m_ID as integer

    Public Overrides ReadOnly Property ID() As Integer
        Get
            Return m_ID
        End Get
    End Property
End Class

...

dim theObject as New MyClass
dim theTree as New BinaryTree(theObject)

Now you can add as many new MyClass objects as you want to the tree by calling AddData:

dim theOtherObject as New MyClass
theTree.AddData(theOtherObject)

The tree uses the inherited ID property to put the objects into the proper order and to find items, so be sure that ID is always unique; for example, the primary key in a SQL table. Also, the tree does type checking to be sure you don't mismatch items since that would mean the possibility of two different IDs which could mess things up, so be sure to use different trees for different types.

If you have any questions or comments, please feel free to contact me. I am busy a lot of the time, but I will try to get back to you as soon as possible ;)

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Polymorpher
Software Developer (Senior) www.ruskin.com
United States United States
PC Programmer/Analyst

You may also be interested in...

Comments and Discussions

 
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.170915.1 | Last Updated 25 Apr 2006
Article Copyright 2006 by Polymorpher
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid