【问题标题】:C: I don't know what this mean "while(temp->next->next)"C:我不知道“while(temp->next->next)”是什么意思
【发布时间】:2020-06-02 04:47:22
【问题描述】:

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

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->nextmean?
我怀疑临时数据类型是 l_List* 而不是 l_List**
为什么这样可以用作二级指针?

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

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

【问题讨论】:

  • 请阅读更多关于C programming language的信息,尤其是阅读Modern C这本书。另请阅读How to debug small programs。使用现代的GCC 编译器,使用gcc -Wall -Wextra -g 进行编译(所有警告和调试信息)。请注意,StackOverflow 不是 do-my-homework 网站
  • C 区分大小写:您的struct linkedListLinkedList* temp 所指的类型不同。请发布您的实际程序源代码。如果这是你的实际程序源代码,那么你需要先整理一下。
  • 使用链表(创建后),->next 指针将指向链表中的下一个节点。所以->next->next指向当前节点temp之后的第二个节点。
  • 下一个问题,请提供一些minimal reproducible example
  • 欢迎来到 SO。为什么你必须怀疑任何事情?如果您有该列表,请查看代码 temp 是什么。没有提到l_List**。你是在哪里拿到的?这里没有 2 级指针用法。最后,向我们展示您想要解释的代码(足够完整,可以编译)。

标签: c linked-list structure


【解决方案1】:

等价于

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;

【讨论】:

    猜你喜欢
    • 2016-03-05
    • 2012-03-24
    • 1970-01-01
    • 1970-01-01
    • 2022-11-28
    • 1970-01-01
    • 1970-01-01
    • 2023-02-26
    • 2013-07-21
    相关资源
    最近更新 更多