FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
java-coding-ninjas/binaryTrees1/NodeWithLargestData.java at master · avinashbest/java-coding-ninjas · GitHub
avinashbest
/
java-coding-ninjas
Public
Notifications
You must be signed in to change notification settings
Fork
11
Star
18
Code
Issues
0
Pull requests
2
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
java-coding-ninjas
/
binaryTrees1
/
NodeWithLargestData.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
23 lines (19 loc) · 900 Bytes
Breadcrumbs
java-coding-ninjas
/
binaryTrees1
/
NodeWithLargestData.java
Copy path
File metadata and controls
23 lines (19 loc) · 900 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package
binaryTrees1
;
import
static
binaryTrees1
.
BinaryTreeInput
.
takeTreeInputDetailed
;
import
static
binaryTrees1
.
BinaryTreeInput
.
printBinaryTree
;
public
class
NodeWithLargestData
{
public
static
int
nodeWithLargestData
(
BinaryTreeNode
<
Integer
>
root
) {
if
(
root
==
null
)
return
-
1
;
int
largestLeft
=
nodeWithLargestData
(
root
.
left
);
int
largestRight
=
nodeWithLargestData
(
root
.
right
);
// comparing three number which one is maximum
return
Math
.
max
(
root
.
data
,
Math
.
max
(
largestLeft
,
largestRight
));
}
public
static
void
main
(
String
[]
args
) {
var
root
=
takeTreeInputDetailed
(
true
,
0
,
true
);
System
.
out
.
println
(
"----------The Tree is----------"
);
printBinaryTree
(
root
);
System
.
out
.
println
(
"-------------------------------"
);
System
.
out
.
println
(
"Node with Largest Data: "
+
nodeWithLargestData
(
root
));
}
}
Back
|
FazBrowse Home
|
New Git URL