首页 > 解决方案 > C: 我不知道“while(temp->next->next)”是什么意思

问题描述

我有一个这样的结构链接列表

typedef struct linkedList l_List;

struct linkedList{
  hash_It* item;     /*this is hashItem structure include key and value*/
  l_List* next;     /*next list                                       */  
};

我的问题是:什么temp->next->next意思?
我怀疑 temp 数据类型l_List*不是l_List**
为什么它可以通过这种方式用作 2 级指针?

cre:我在另一个来源找到了这段代码

l_List* temp = list;
    while (temp->next->next) {
        temp = temp->next;
    }

标签: clinked-liststructure

解决方案


它相当于

l_List* find(l_list *temp)
{
    while (temp->next) 
    {
        l_list *temp1 = temp -> next;
        if(temp1 -> next == NULL)
            break; 
        temp = temp->next;
    }
    return  temp;
}

它应该可以帮助您理解它的含义。

    l_list *temp1 = temp -> next -> next;

是相同的

    l_list *temp1 = temp -> next;
    temp1 = temp1 -> next;

推荐阅读