public object visit(EmptyNode emptyNode)
        {
            NonEmptyNode newNode = (NonEmptyNode)BSTBuilder.getNodeFactory().createNonEmptyNode(newKey);

            newNode.setLeft(EmptyNode.getInstance());
            newNode.setRight(EmptyNode.getInstance());
            return(newNode);
        }
Beispiel #2
0
 public static EmptyNode getInstance()
 {
     if (instance == null)
     {
         instance = new EmptyNode();
     }
     return(instance);
 }
Beispiel #3
0
 public BSTree(int[] a)
 {
     a    = a.Distinct().ToArray();
     root = new NonEmptyNode(a[0]);
     root.setLeft(EmptyNode.getInstance());
     root.setRight(EmptyNode.getInstance());
     for (int i = 1; i < a.Length; i++)
     {
         insert(a[i]);
     }
 }
Beispiel #4
0
 public BSTree(int[] a, bool isBalancedTree)
 {
     a = a.Distinct().ToArray();
     if (isBalancedTree)
     {
         Array.Sort(a);
         root = BSTBuilder.sortedArrayToBST(a, 0, a.Length - 1);
     }
     else
     {
         root = new NonEmptyNode(a[0]);
         root.setLeft(EmptyNode.getInstance());
         root.setRight(EmptyNode.getInstance());
         for (int i = 1; i < a.Length; i++)
         {
             insert(a[i]);
         }
     }
 }
 public object visit(EmptyNode emptyNode)
 {
     return(-1);
 }
Beispiel #6
0
 public object visit(EmptyNode emptyNode)
 {
     Console.WriteLine(x + " doesn't exists!");
     return(emptyNode);
 }
Beispiel #7
0
 public BSTree()
 {
     root = EmptyNode.getInstance();
 }
Beispiel #8
0
 public Node createEmptyNode()
 {
     return(EmptyNode.getInstance());
 }