// A utility function to // find deepest leaf node. // lvl: level of current node. // isLeft: A bool indicate // that this node is left child public virtual void deepestLeftLeafUtil(Node2 node, int lvl, Level level, bool isLeft) { // Base case if (node == null) { return; } // Update result if this node // is left leaf and its level // is more than the maxl level // of the current result if (isLeft != false && node.left == null && node.right == null && lvl > level.maxlevel) { result = node; level.maxlevel = lvl; } // Recur for left and right subtrees deepestLeftLeafUtil(node.left, lvl + 1, level, true); deepestLeftLeafUtil(node.right, lvl + 1, level, false); }
// A wrapper over deepestLeftLeafUtil(). public virtual void deepestLeftLeaf(Node2 node) { Level level = new Level(); deepestLeftLeafUtil(node, 0, level, false); }
// Constructor public Node2(int data) { this.data = data; left = right = null; }