Java Reference
In-Depth Information
39
40 // post: prints in preorder the tree with given root
41 private void printPreorder(IntTreeNode root) {
42 if (root != null) {
43 System.out.print(" " + root.data);
44 printPreorder(root.left);
45 printPreorder(root.right);
46 }
47 }
48
49 // post: prints the tree contents using an inorder traversal
50 public void printInorder() {
51 System.out.print("inorder:");
52 printInorder(overallRoot);
53 System.out.println();
54 }
55
56 // post: prints in inorder the tree with given root
57 private void printInorder(IntTreeNode root) {
58 if (root != null) {
59 printInorder(root.left);
60 System.out.print(" " + root.data);
61 printInorder(root.right);
62 }
63 }
64
65 // post: prints the tree contents using a postorder traversal
66 public void printPostorder() {
67 System.out.print("postorder:");
68 printPostorder(overallRoot);
69 System.out.println();
70 }
71
72 // post: prints in postorder the tree with given root
73 private void printPostorder(IntTreeNode root) {
74 if (root != null) {
75 printPostorder(root.left);
76 printPostorder(root.right);
77 System.out.print(" " + root.data);
78 }
79 }
80
81 // post: prints the tree contents, one per line, following an
82 // inorder traversal and using indentation to indicate
Search WWH ::




Custom Search