예제 #1
0
  public static void main(String[] args) {
    Tree myTree = new Tree();

    myTree.insert(50);
    myTree.insert(11);
    myTree.insert(54);
    myTree.insert(45);
    myTree.insert(21);
    myTree.insert(82);
    myTree.insert(3);

    myTree.find(50);
    myTree.find(21);
    myTree.find(100); // test finding a non-existing node

    myTree.traverse(0); // in-order traverse

    myTree.getSuccessor2(myTree.root);
    myTree.getSuccessor2(myTree.root.leftChild); // look for successor of 11

    myTree.remove(82); // remove type 1
    System.out.print("After removing 82, the tree is :");
    myTree.traverse(0);
    myTree.insert(82); // recover
    System.out.print("After recovering 82, the tree is :");
    myTree.traverse(0);
    myTree.remove(54); // remove type 2
    System.out.print("After removing 54, the tree is :");
    myTree.traverse(0);
    myTree.remove(11); // remove type 3
    System.out.print("After removing 11, the tree is :");
    myTree.traverse(0);
  }
예제 #2
0
 public static void main(String[] args) {
   Tree<Integer> tree = new Tree<>();
   tree.add(tree.root, 7);
   tree.add(tree.root, 3);
   tree.add(tree.root, 1);
   tree.add(tree.root, 25);
   tree.add(tree.root, 77);
   tree.add(tree.root, 2);
   tree.add(tree.root, 6);
   System.out.println(tree.find(6));
   System.out.println(tree.findRec(tree.root, 6));
   System.out.println(tree.findFstKeyLargerK(64));
   System.out.println(tree.findFstKeyLargerK(1));
 }
예제 #3
0
파일: App.java 프로젝트: H35am/Tree
  /**
   * De main wordt gebruikt om de tree te testen.
   *
   * @param args
   */
  public static void main(String[] args) {
    //		Programmeer een paar cases waarbij
    //		je laat zien dat de boom werkt
    Tree tree = new Tree();
    Student student = new Student(1, "Kees");
    Student student1 = new Student(2, "Jan");

    tree.insert(student);
    tree.insert(student1);

    Student findStudent = tree.find(2);

    System.out.print(findStudent.toString());

    //		voeg studenten met studentnummers �0802063� tot en met �0824836� toe

    //		Verwijder de root

    //		print de studenten op volgorde van studentnummer
  }