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