//Dem Node bac 1 private int countB1 (Node t){ if (t==null) return 0; else if((t.right==null&&t.left!=null)||(t.right!=null&&t.left==null)) return 1+countB1(t.left)+countB1(t.right); else return countB1(t.left)+countB1(t.right); } public void countB1(){ System.out.println(countB1(r)); } // bac 2 cua cay private int countB2(Node t){ if(t==null) return 0; else if(t.left==null||t.right==null) return countB2(t.left)+countB2(t.right); else return 1+ countB2(t.left)+countB2(t.right); } public void countB2(){ System.out.println(countB2(r)); }
Không có nhận xét nào: