-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostOrderTraversal.java
More file actions
46 lines (30 loc) · 883 Bytes
/
Copy pathpostOrderTraversal.java
File metadata and controls
46 lines (30 loc) · 883 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* you only have to complete the function given below.
Node is defined as
class Node {
int data;
Node left;
Node right;
}
*/
void postOrder(Node root) {
//this is a recursive function
// therefore it should have base case first
// and then secondly the recursive case
//1] the base case
//if root is null then return
//post order the left
//post order the right
// then print the data
if(root == null){
return;
} else {
//assume the recursion fairy will print everything on the left
//then print everything on the right and then all you have to do is to
//print the root data
postOrder(root.left);
postOrder(root.right);
System.out.print(root.data + " ");
}
//if you reach null return
//else
}