Skip to content

Commit d1a5240

Browse files
committed
Tree Updates
Tree Updates
1 parent 048a426 commit d1a5240

File tree

7 files changed

+92
-7
lines changed

7 files changed

+92
-7
lines changed
546 Bytes
Binary file not shown.
743 Bytes
Binary file not shown.
743 Bytes
Binary file not shown.

src/chapter3linkedlists/LinkedList.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public String toString() {
170170
return result+"]";
171171
}
172172
result = result + head.getData();
173-
ListNode temp = head.getNext();;
173+
ListNode temp = head.getNext();
174174
while (temp != null) {
175175
result = result + "," + temp.getData();
176176
temp = temp.getNext();

src/chapter6trees/BinaryTreeNode.java

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,31 @@
1212

1313
package chapter6trees;
1414

15-
public class BinaryTreeNode {
16-
int data;
17-
BinaryTreeNode left;
18-
BinaryTreeNode right;
19-
BinaryTreeNode(int x) {
20-
data = x;
15+
public class BinaryTreeNode {
16+
public int data;
17+
public BinaryTreeNode left;
18+
public BinaryTreeNode right;
19+
public BinaryTreeNode(int data){
20+
this.data = data;
2121
left = null;
2222
right = null;
2323
}
24+
public int getData() {
25+
return data;
26+
}
27+
public void setData(int data) {
28+
this.data = data;
29+
}
30+
public BinaryTreeNode getLeft() {
31+
return left;
32+
}
33+
public void setLeft(BinaryTreeNode left) {
34+
this.left = left;
35+
}
36+
public BinaryTreeNode getRight() {
37+
return right;
38+
}
39+
public void setRight(BinaryTreeNode right) {
40+
this.right = right;
41+
}
2442
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package chapter6trees;
2+
3+
/*Copyright (c) Dec 21, 2014 CareerMonk Publications and others.
4+
* E-Mail : info@careermonk.com
5+
* Creation Date : 2015-01-10 06:15:46
6+
* Last modification : 2006-05-31
7+
by : Narasimha Karumanchi
8+
* File Name : MaxInBinaryTree.java
9+
* Book Title : Data Structures And Algorithms Made In Java
10+
* Warranty : This software is provided "as is" without any
11+
* warranty; without even the implied warranty of
12+
* merchantability or fitness for a particular purpose.
13+
*
14+
*/
15+
16+
public class MaxInBinaryTreeRecursive {
17+
public int maxInBinaryTree(BinaryTreeNode root){
18+
int maxValue = Integer.MIN_VALUE;
19+
if (root != null){
20+
int leftMax = maxInBinaryTree(root.left);
21+
int rightMax = maxInBinaryTree(root.right);
22+
23+
if (leftMax > rightMax)
24+
maxValue = leftMax;
25+
else
26+
maxValue = rightMax;
27+
28+
if (root.data > maxValue)
29+
maxValue = root.data;
30+
}
31+
return maxValue;
32+
}
33+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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 : MinInBinaryTreeRecursive.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 MinInBinaryTreeRecursive {
18+
public int minInBinaryTree(BinaryTreeNode root){
19+
int minValue = Integer.MAX_VALUE;
20+
if (root != null){
21+
int leftMin = minInBinaryTree(root.left);
22+
int rightMin = minInBinaryTree(root.right);
23+
24+
if (leftMin > rightMin)
25+
minValue = leftMin;
26+
else
27+
minValue = rightMin;
28+
29+
if (root.data < minValue)
30+
minValue = root.data;
31+
}
32+
return minValue;
33+
}
34+
}

0 commit comments

Comments
 (0)