public void findMax(Node node) {
int root_val,max_val=0;
if(null!=node) {
Queue<Node> queue = new LinkedBlockingQueue<>();
queue.add(node);
while(!queue.isEmpty()) {
Node temp = queue.remove();
root_val = temp.value;
max_val = max_val<root_val ? root_val :max_val;
if(null!=temp.left) {
queue.add(temp.left);
}
if(null!=temp.right) {
queue.add(temp.right);
}
}
}
System.out.println(max_val);
}
int root_val,max_val=0;
if(null!=node) {
Queue<Node> queue = new LinkedBlockingQueue<>();
queue.add(node);
while(!queue.isEmpty()) {
Node temp = queue.remove();
root_val = temp.value;
max_val = max_val<root_val ? root_val :max_val;
if(null!=temp.left) {
queue.add(temp.left);
}
if(null!=temp.right) {
queue.add(temp.right);
}
}
}
System.out.println(max_val);
}
No comments:
Post a Comment