Esempio n. 1
0
        public void insert(double key, string val)
        {
            BSTNode itr = root;
            BSTNode parent = null;

            if (itr == null)
            {
                root = new BSTNode(key, val, parent);
                return;
            }

            while (itr != null)
            {
                parent = itr;
                if (itr.key >= key)
                    if (itr.left != null)
                        itr = itr.left;
                    else
                    {
                        itr.left = new BSTNode(key, val, parent);
                        return;
                    }
                else
                    if (itr.right != null)
                        itr = itr.right;
                    else
                    {
                        itr.right = new BSTNode(key, val, parent);
                        return;
                    }
            }
        }
Esempio n. 2
0
 public BSTNode(double key, string val, BSTNode parent)
 {
     this.key = key;
     this.value = val;
     this.right = null;
     this.left = null;
     this.parent = parent;
 }
Esempio n. 3
0
 public List<string> inOrderTraversal(BSTNode n, List<string> list)
 {
     if (n == null)
         return list;
     inOrderTraversal(n.left, list);
     list.Add(n.value);
     inOrderTraversal(n.right, list);
     return list;
 }