位置:学校首页 > 学校动态>苏州师资专业的Java机构
达内致力于面向IT互联网行业,培养软件开发工程师、测试工程师、系统管理员、智能硬件工程师、UI设计师、网络营销工程师、会计等职场人才。2015年起,推出面向青少年的少儿编程、智能机器人编程、编程数学等K12课程
Java算法:递归二叉树算法
二叉树的本质是递归结构,很多可以使用递归分治法完成的,推广了遍历算法。
在只给定指向树的一个指针的前提下,经常需要找到树的各种结构参数的值。
树参数的计算,树的结点树和高度
private static int count(Node h){ if(h == null){ reutrn 0; } return count(h.l) + count(h.r) + 1; } int count(){ return count(root); } private static int height(Node h){ if(h == null){ return -1; } int u = height(h.l), v = height(h.r); if(u > v){ return u + 1; }else{ return v + 1; } } int height(){ return height(root); }