这两个功能有什么区别吗?我的意思是返回的结果?
int Length(struct node* head) {
struct node* current = head;
int count = 0;
while (current != NULL) {
count++;
current = current->next;
}
return count;
}
Run Code Online (Sandbox Code Playgroud)
和这个功能
int Length(struct node* head) {
int count = 0;
while (head != NULL) {
count++;
head = head->next;
}
return count;
}
Run Code Online (Sandbox Code Playgroud)
他们是一样的.一个使用本地"当前"变量迭代列表,而另一个使用通过函数参数接收的相同变量.