我尝试了很多编码来解决以下问题,但也找不到答案。谁能帮我解决我的问题并告诉我哪里编码错误?
/** Task: Recusively counts the nodes in a chain.
* @param start the first node
* @returns the number of nodes in the linked chain */
public int countNodes(Node start)
{
if (start == null)
// base case
{
countNodes (Node start);
// recursive case
else
System.out.println (start.data);
return start.next;
}
} // end countNodes
最佳答案
也许这样想会有所帮助:当前节点的节点数为 1 加上其余节点的计数结果。
关于java - 编写一个递归方法来计算链接节点链中的节点数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3674956/