程序填空题:递归求单链表长度
本题要求采用递归方式求不带头结点的单链表的长度。
其中, 单链表结点类型定义如下:
```c++
typedef struct LNode {
int data;
struct LNode* next;
} LinkNode;
```
```c++
///求单链表长度
int getLength(LinkNode* L) {
if (L == NULL)
return 0;
return @@[1 + getLength(L->next)](4);
}
```
答案:
第1空:1 + getLength(L->next)
其中, 单链表结点类型定义如下:
```c++
typedef struct LNode {
int data;
struct LNode* next;
} LinkNode;
```
```c++
///求单链表长度
int getLength(LinkNode* L) {
if (L == NULL)
return 0;
return @@[1 + getLength(L->next)](4);
}
```
答案:
第1空:1 + getLength(L->next)