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 | - | // TODO Auto-generated method stub |
10 | + | |
11 | - | new BinaryNode<Character>('x'); |
11 | + | |
12 | int m = (int) Math.pow(2,n)-1; | |
13 | BinaryNode<Character>[] array = new BinaryNode<Character>[m]; | |
14 | ||
15 | for (Character c : input.nextLine().toCharArray()) { | |
16 | array[i] = new BinaryNode<Character>(Character.isLetter(c) ? c : null); | |
17 | - | //assigns to null |
17 | + | |
18 | BinaryNode<Character> root = array[0]; | |
19 | ||
20 | // HERE: turn the flat, unrelated array of BinaryNode's into a real tree starting with root. | |
21 | ||
22 | - | System.out.println(n); |
22 | + | System.out.println(root.toStringPreOrder()); |
23 | System.out.println(root.toStringInOrder()); | |
24 | System.out.println(root.toStringPostOrder()); | |
25 | // done! | |
26 | } | |
27 | } |