// ----------------------------------------------------------- // Estruturas de Dados 2019/2020 (CC1007) - DCC/FCUP // http://www.dcc.fc.up.pt/~pribeiro/aulas/edados1920/ // ----------------------------------------------------------- // Classe utilitaria com metodo para ler uma arvore em preorder // Ex: 5 1 8 N N 6 N N 7 2 N N N // Ultima alteracao: 26/04/2018 // ----------------------------------------------------------- import java.util.Scanner; public class LibBTree { public static BTree readIntTree(Scanner in) { BTree t = new BTree(); t.setRoot(readIntNode(in)); return t; } private static BTNode readIntNode(Scanner in) { String s = in.next(); if (s.equals("N")) return null; Integer value = Integer.parseInt(s); BTNode left = readIntNode(in); BTNode right = readIntNode(in); return new BTNode(value, left, right); } }