View difference between Paste ID: 6QMahGAv and ZnTbjyGS
SHOW: | | - or go back to the newest paste.
1
import java.io.*;
2
import java.util.*;
3
4
public class BinaryTreeTraversal {
5
6
    /**
7
     * @param args
8
     */
9
    public static void main(String[] args) {
10
        Scanner input = new Scanner("input.txt");
11
        int n = input.nextInt();
12
        int m = (int) Math.pow(2,n)-1;
13-
        List<BinaryNode<Character>> list = new ArrayList<BinaryNode<Character>>(m);
13+
        List<BinaryNode<Character>> list = new ArrayList<BinaryNode<Character>>();
14
        
15
        for (Character c : input.nextLine().toCharArray()) {
16
            list.add(new BinaryNode<Character>(Character.isLetter(c) ? c : null));
17
        }
18
        BinaryNode<Character> root = list.get(0);
19
        
20
        // HERE: turn the flat, unrelated array of BinaryNode's into a real tree starting with root.
21
22
        System.out.println(root.toStringPreOrder());
23
        System.out.println(root.toStringInOrder());
24
        System.out.println(root.toStringPostOrder());
25
        // done!
26
    }
27
}