假设我有以下结构来定义列表节点:
 struct node {
         int            data;
         struct node*   next;
};
我有这个函数来获取列表的长度:
int Length(struct node* head) {
   struct node* current = head;
   int count = 0;
   while (current != NULL) {
      count++;
      current = current->next;
   }
   return count;
}
我为什么要这样做:struct node* current = head;而不是仅仅在头上迭代?
那么,为什么这不行:
int Length(struct node* head) {
   int count = 0;
   while (head != NULL) {
      count++;
      head = head->next;
   }
   return count;
}
head 进入 Length 函数后是否会失去作用域,因此即使我们执行 head = head->next 它也不会在函数之外受到影响?
谢谢