public int findMax(Node node) {
int maxVal = 0, root_val ,left_val,right_val;
if(null!=node) {
root_val = node.value;
left_val = findMax(node.left);
right_val = findMax(node.right);
maxVal = left_val>right_val ? left_val :right_val;
maxVal = maxVal>root_val ? maxVal : root_val;
}
return maxVal;
}
int maxVal = 0, root_val ,left_val,right_val;
if(null!=node) {
root_val = node.value;
left_val = findMax(node.left);
right_val = findMax(node.right);
maxVal = left_val>right_val ? left_val :right_val;
maxVal = maxVal>root_val ? maxVal : root_val;
}
return maxVal;
}
No comments:
Post a Comment