Home
GitHub
Solve Program
Tutorials and Solve Programming Problems
≡
Home
Java
PHP
Home
»
algorithm
»
binary-tree
»
data-structure
»
java
»
How to Find Maximum Leaf or Node Value from Tree - Java
How to Find Maximum Leaf or Node Value from Tree - Java
By Solve Program
How to Find Maximum Leaf or Node Value from Tree - Java
Java Programming
Node Class
public class Node { public int id; public String data; public Node leftChild; public Node rightChild; Node(int id) { this.id = id; leftChild = null; rightChild = null; } public void displayNode() { System.out.print("( " + id + ", " + data + " )"); } }
Find maximum leaf method in binary tree
public Node findMaximum(Node node) { if (node.rightChild != null) { return findMaximum(node.rightChild); } return node; }
Case for show maximum leaf value from the tree
int choice = getChar(); switch (choice) { case 'n': Node maxNode = theTree.findMaximum(theTree.root); System.out.println("Maximum node value is " + maxNode.id); break; }
Related Solving and Tutorial:
Find The Power Of Number - Java
Find Factorial - Java
Stack - Java
Queue - Java
Selection Sort - Java
Insertion Sort - Java
Newer Post
Older Post
Home
Programming Language
Java
PHP
Data Structure
All Data Structure
Array
Sort
Stack
Queue