0

如何使用递归计算单链表节点的数量(只有 if 语句没有 while 或 for 循环)

int Elements(Node head)
{
    if (head==null)
        return 0;
    else
    {

    }
    head=head.next;
}
4

1 回答 1

5
int Elements(Node head)
{
    if (head==null)
        return 0;
    else
        return 1 + Elements(head.next);
}
于 2013-11-05T02:10:01.893 回答