How do you search an album in a listBox and connect it to an AVL tree or a Binary Search Tree? C#
<p>I need the albums that appear in the listbox, to have a search function that passes through the AVL Tree or Binary Search Tree.</p>

<p>This is my code for the AVLTree class</p>

<pre><code>    class AVLTree&lt;T&gt; : BSTree&lt;T&gt; where T : IComparable
    {
        public new void InsertItem(T item)
        {
            insertItem(item, ref root);
        }

        private void insertItem(T item, ref Node&lt;T&gt; tree)
        {
                 if (tree == null)
            tree = new Node&lt;T&gt;(item);
        else if (item.CompareTo(tree.Data) &lt; 0)
            insertItem(item, ref tree.Left);
        else if (item.CompareTo(tree.Data) &gt; 0)
        insertItem (item, ref tree.Right);
                 tree.balanceFactor = Height(tree.Left)-Height(tree.Right);
                 if (tree.balanceFactor &lt;= -2)
                     rotateLeft(ref tree);
                 if (tree.balanceFactor &gt;= 2)
                     rotateRight(ref tree);



       }


        private void rotateLeft(ref Node&lt;T&gt; tree)
        {             

            if (tree.Right.balanceFactor &gt; 0)  
                rotateRight(ref tree.Right);
            Node&lt;T&gt; pivot = tree.Right;
            tree.Right = pivot.Left;
            pivot.Left = tree;
            tree = pivot;



        }

        private void rotateRight(ref Node&lt;T&gt; tree)
        {

            if (tree.Left.balanceFactor &gt; 0) 
                rotateLeft(ref tree.Left);
            Node&lt;T&gt; pivot = tree.Left;              
            tree.Left = pivot.Right;
            pivot.Right = tree;
            tree = pivot;
        }
    }

}
</code></pre>

<p>FormClass:</p>

<p>//search button</p>

<pre><code>    private void Search_Click(object sender, EventArgs e) //BASIC SEARCH NOT SUITABLE YET
    {
        listBox1.ClearSelected();
        int index = listBox1.FindString(SearchText.Text);
        if (index &lt;0)

        {
            MessageBox.Show("Item not found.");
            SearchText.Text = String.Empty;
        }
        else
        {
            listBox1.SelectedIndex = index;
        }
</code></pre>

<p>.</p>

<p>//ARTIST CLASS
{
    class Artist : IComparable
    {</p>

<pre><code>    public String name; //changed to public
    public String member;
    public LinkedList&lt;String&gt; Album;

    public Artist(String artistname, String members, String[] albName) 
        {
            name = artistname;
            member = members;
            Album = new LinkedList&lt;String&gt;(albName);
        }

    public LinkedList&lt;String&gt; getAlbum()
    {
        return Album;
    }

    public int CompareTo(object obj)
    {
        if (obj is Artist) //Artist name comparison
        {
            Artist other = (Artist)obj;
            return name.CompareTo(other.name);
        }
        if (obj is string) //Album comparison
        {
            Artist other = (Artist)obj;
            return name.CompareTo(other.Album);
        }
        else
            return -999;  //Comparison can not be made
    }
}
</code></pre>

<p>}</p>

<p>//ALBUM  CLASS</p>

<p>class Album
    {</p>

<pre><code>    private String title;
    private String daterel;

    public Album(String aTitle, String saleDate) 
    {
        daterel = saleDate;
        title = aTitle;           
    }
}
</code></pre>

<p>}</p>
