Esempio n. 1
0
        public void insert(T i)
        {
            CNode <T> newNode = new CNode <T>();

            newNode.data = i;
            try
            {
                if (root == null)
                {
                    root = newNode;
                }
                else
                {
                    CNode <T> current = root;
                    CNode <T> parrent;

                    while (true)
                    {
                        parrent = current;

                        if (i.ToString().CompareTo(current.data.ToString()) > 0)
                        {
                            current = current.Left;

                            if (current == null)
                            {
                                parrent.Left = newNode;

                                break;
                            }
                        }
                        else
                        {
                            current = current.Right;

                            if (current == null)
                            {
                                parrent.Right = newNode;

                                break;
                            }
                        }
                    }
                }
            }catch (Exception e) { }
        }
Esempio n. 2
0
        public CNode <T> Find(T key)
        {
            CNode <T> current = root;

            while (!current.data.Equals(key))
            {
                if (key.ToString().CompareTo(current.data.ToString()) > 0)
                {
                    current = current.Left;
                }
                else
                {
                    current = current.Right;
                }
                if (current == null)
                {
                    return(null);
                }
            }
            return(current);
        }
Esempio n. 3
0
 public binarySearchTree()
 {
     root = null;
 }