Skip to content

Commit 2baddfe

Browse files
committed
Tree Updates
Tree Updates
1 parent 6b9ce0a commit 2baddfe

16 files changed

+285
-0
lines changed
746 Bytes
Binary file not shown.

bin/chapter6trees/DeepestNode.class

1 KB
Binary file not shown.
295 Bytes
Binary file not shown.
1.12 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*Copyright (c) Dec 21, 2014 CareerMonk Publications and others.
2+
* E-Mail : info@careermonk.com
3+
* Creation Date : 2015-01-10 06:15:46
4+
* Last modification : 2006-05-31
5+
by : Narasimha Karumanchi
6+
* File Name : CheckStructurullySameTrees.java
7+
* Book Title : Data Structures And Algorithms Made In Java
8+
* Warranty : This software is provided "as is" without any
9+
* warranty; without even the implied warranty of
10+
* merchantability or fitness for a particular purpose.
11+
*
12+
*/
13+
14+
15+
package chapter6trees;
16+
17+
public class CheckStructurullySameTrees {
18+
public boolean checkStructurullySameTrees(BinaryTreeNode root1, BinaryTreeNode root2) {
19+
if(root1 == null && root2 == null)
20+
return true;
21+
if(root1 == null || root2 == null)
22+
return false;
23+
return (checkStructurullySameTrees(root1.getLeft(), root2.right) &&
24+
checkStructurullySameTrees(root1.right, root2.getLeft()));
25+
}
26+
}

src/chapter6trees/DeepestNode.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*Copyright (c) Dec 21, 2014 CareerMonk Publications and others.
2+
* E-Mail : info@careermonk.com
3+
* Creation Date : 2015-01-10 06:15:46
4+
* Last modification : 2006-05-31
5+
by : Narasimha Karumanchi
6+
* File Name : DeepestNode.java
7+
* Book Title : Data Structures And Algorithms Made In Java
8+
* Warranty : This software is provided "as is" without any
9+
* warranty; without even the implied warranty of
10+
* merchantability or fitness for a particular purpose.
11+
*
12+
*/
13+
14+
15+
package chapter6trees;
16+
17+
import java.util.LinkedList;
18+
import java.util.Queue;
19+
20+
public class DeepestNode {
21+
// The last node processed from queue in level order is the deepest node in binary tree.
22+
public BinaryTreeNode deepestNodeinBinaryTree(BinaryTreeNode root) {
23+
BinaryTreeNode tmp = null;
24+
if(root == null)
25+
return null;
26+
Queue<BinaryTreeNode> q = new LinkedList<BinaryTreeNode>();
27+
q.offer(root);
28+
while(!q.isEmpty()){
29+
tmp = q.poll();
30+
if(tmp.getLeft() != null)
31+
q.offer(tmp.getLeft());
32+
if(tmp.right != null)
33+
q.offer(tmp.right);
34+
}
35+
return tmp;
36+
}
37+
}

0 commit comments

Comments
 (0)