Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Created by Julio Tentor <jtentor@fi.unju.edu.ar>
- //
- import java.util.Random;
- import java.util.Scanner;
- public class DemoTree2 {
- public static void main(String[] args) {
- System.out.println("Demo Arbol Binario de Búsqueda");
- BinarySearchTree<Integer> bst = new BinarySearchTree<Integer>();
- Random random = new Random();
- Integer number;
- for (int i = 0; i < 10; ++i) {
- number = (Integer) random.nextInt(100) + 1;
- bst.add(number);
- }
- System.out.printf("Arbol %s", bst.toString());
- System.out.println();
- System.out.print("Pre Orden ");
- bst.PreOrder();
- System.out.println();
- System.out.print("En Orden ");
- bst.InOrder();
- System.out.println();
- System.out.print("Post Orden ");
- bst.PostOrder();
- System.out.println();
- System.out.print("Descendente ");
- bst.DescendingOrder();
- System.out.println();
- System.out.printf("Cantidad de Nodos %s\n", bst.NodeCount());
- System.out.printf("Cantidad de Hojas %s\n", bst.LeafCount());
- System.out.printf("Nodos Internos %s\n", bst.InternalCount());
- System.out.printf("Máximo Nivel %s\n", bst.MaxLevel());
- System.out.printf("Altura %s\n", bst.Height());
- System.out.println("\nDemo Arbol Binario de Búsqueda Extracción");
- Scanner scanner = new Scanner(System.in);
- while (true) {
- System.out.printf("Arbol...: %s\n", bst.toString());
- System.out.printf("En Orden: ");
- bst.InOrder();
- System.out.println();
- System.out.printf("Ingrese valor a remover (0 finaliza) ");
- number = scanner.nextInt();
- if (number == 0) {
- break;
- }
- try {
- bst.remove(number);
- } catch (Exception e) {
- System.out.println(e.getMessage());
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement