批作业,其中有道题目是写一个method,求一个binary tree的所有节点(整数)的平均值,要求用递归。可以用一个方法size()得到tree的接点数。有三分之一的学生的代码是这样的:
if ( left != null && right != null)
return ( this + left.avg() + right.avg() ) / 3
else if ( left != null )
return ( this + left.avg() ) / 2
else if ( right != null )
return ( this + right.avg() ) / 2
else
return this
I haven't seen so stupid error in my classmates when I took undergraduate program in China. These students are first year students at U of Waterloo, CS. Only one third of them will get bachelor degree in CS here.
-smallwhale(小京);
2001-11-20(#268143@0)
U of Waterloo? CS? 哈哈,我想大家都没啥好说的了。
-liyaobin(BigBen);
2001-11-20(#268146@0)