public HuffmanTree(Scanner input) { while (input.hasNextLine()) { char data = (char) Integer.parseInt(input.nextLine()); String code = input.nextLine(); read(overallRoot, data, code); } } private void read(HuffmanNode root, char data, String code) { if (code.isEmpty()) { root = new HuffmanNode(data, -1); } else { if (root == null) { root = new HuffmanNode(-1, null, null); } if (code.charAt(0) == '0') { read(root.left, data, code.substring(1)); } else { read(root.right, data, code.substring(1)); } } }