mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-18 17:31:13 +08:00
source coding is a little complex
This commit is contained in:
@ -37,14 +37,10 @@ public class LevelOrderTraversal
|
|||||||
return 0;
|
return 0;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* compute height of each subtree */
|
/**
|
||||||
int lheight = height(root.left);
|
* return the larger one;
|
||||||
int rheight = height(root.right);
|
*/
|
||||||
|
return Math.max(height(root.left),height(root.right)) + 1;
|
||||||
/* use the larger one */
|
|
||||||
if (lheight > rheight)
|
|
||||||
return(lheight+1);
|
|
||||||
else return(rheight+1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,4 +71,4 @@ public class LevelOrderTraversal
|
|||||||
System.out.println("Level order traversal of binary tree is ");
|
System.out.println("Level order traversal of binary tree is ");
|
||||||
tree.printLevelOrder();
|
tree.printLevelOrder();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user