Esempio n. 1
0
 public Node(int value, int key)
 {
     this.key = key;
     this.value = value;
     left = null;
     right = null;
 }
Esempio n. 2
0
        public void insert(int k)
        {
            Node z = new Node(k, count);
            count++;
            Node y = NIL;
            Node x = dictionary[0];

            while (x != NIL)
            {
                y = x;
                if (z.Value < x.Value)
                {
                    x = dictionary[left(x.Key)];
                }
                else
                {
                    x = dictionary[right(x.Key)];
                }
            }
            z.Parent = y;
            if (y == NIL)
            {
                dictionary[0] = z;
            }
            else if (z.Value < y.Value)
            {
                dictionary[left(y.Key)] = z;
            }
            else
            {
                dictionary[right(x.Key)] = z;
            }
        }
Esempio n. 3
0
 public bool search(int k)
 {
     Node kNode = new Node(k, 0);
     if (treeSearch(dictionary[0], kNode) != null)
     {
         if (kNode.Value == treeSearch(dictionary[0], kNode).Value)
         {
             return true;
         }
         else
             return false;
     }
     else
         return false;
 }
Esempio n. 4
0
 private List<int> inOrderTreeWalk(Node x)
 {
     int[] list = new int[dictionary.Length];
     if (x != NIL)
     {
         inOrderTreeWalk(dictionary[left(x.Key)]);
         al.Add(x.Value);
         inOrderTreeWalk(dictionary[right(x.Key)]);
     }
     return al;
 }
Esempio n. 5
0
 private Node treeSearch(Node x, Node k)
 {
     if (x == NIL || k.Value == x.Value)
     {
         return x;
     }
     if (k.Value < x.Value)
     {
         return treeSearch(dictionary[left(x.Key)], k);
     }
     else
     {
         return treeSearch(dictionary[right(x.Key)], k);
     }
 }