Beispiel #1
0
  public void testPreorder() {
    BSTNode<String, String> one = new BSTNode<String, String>("a", "1");
    BSTNode<String, String> two = new BSTNode<String, String>("b", "2");
    BSTNode<String, String> three = new BSTNode<String, String>("c", "3");
    BSTNode<String, String> four = new BSTNode<String, String>("d", "4");
    BSTNode<String, String> five = new BSTNode<String, String>("e", "5");
    BSTNode<String, String> six = new BSTNode<String, String>("f", "6");
    BSTNode<String, String> seven = new BSTNode<String, String>("g", "7");
    BSTNode<String, String> eight = new BSTNode<String, String>("h", "8");
    BSTNode<String, String> nine = new BSTNode<String, String>("i", "9");
    BSTNode<String, String> ten = new BSTNode<String, String>("j", "10");
    BSTNode<String, String> eleven = new BSTNode<String, String>("k", "11");

    one.setLeft(two);
    one.setRight(three);
    two.setRight(seven);
    three.setLeft(four);
    three.setRight(six);
    four.setRight(five);
    six.setLeft(eight);
    six.setRight(nine);
    seven.setLeft(eleven);
    eight.setLeft(ten);

    RegBST<String, String> tree = new RegBST<String, String>();
    tree.setRoot(one);

    assertEquals("a b g k c d e f h j i ", tree.preorder());
  }
Beispiel #2
0
  public RegBST<Integer, String> genRemove() {
    RegBST<Integer, String> tree = new RegBST<Integer, String>();

    BSTNode<Integer, String> a = new BSTNode<Integer, String>(30, "a");
    BSTNode<Integer, String> b = new BSTNode<Integer, String>(17, "b");
    BSTNode<Integer, String> c = new BSTNode<Integer, String>(55, "c");
    BSTNode<Integer, String> d = new BSTNode<Integer, String>(5, "d");
    BSTNode<Integer, String> e = new BSTNode<Integer, String>(45, "e");
    BSTNode<Integer, String> f = new BSTNode<Integer, String>(67, "f");
    BSTNode<Integer, String> g = new BSTNode<Integer, String>(3, "g");
    BSTNode<Integer, String> h = new BSTNode<Integer, String>(10, "h");
    BSTNode<Integer, String> i = new BSTNode<Integer, String>(31, "i");
    BSTNode<Integer, String> j = new BSTNode<Integer, String>(47, "j");
    BSTNode<Integer, String> k = new BSTNode<Integer, String>(60, "k");
    BSTNode<Integer, String> l = new BSTNode<Integer, String>(4, "l");
    BSTNode<Integer, String> m = new BSTNode<Integer, String>(9, "m");
    BSTNode<Integer, String> n = new BSTNode<Integer, String>(46, "n");
    BSTNode<Integer, String> o = new BSTNode<Integer, String>(58, "o");
    BSTNode<Integer, String> p = new BSTNode<Integer, String>(63, "p");
    BSTNode<Integer, String> q = new BSTNode<Integer, String>(62, "q");

    a.setLeft(b);
    a.setRight(c);
    b.setLeft(d);
    c.setLeft(e);
    c.setRight(f);
    d.setLeft(g);
    d.setRight(h);
    e.setLeft(i);
    e.setRight(j);
    f.setLeft(k);
    g.setRight(l);
    h.setLeft(m);
    j.setLeft(n);
    k.setLeft(o);
    k.setRight(p);
    p.setLeft(q);

    tree.setRoot(a);

    return tree;
  }