Search code examples
clinked-liststructure

C: I don't know what this mean "while(temp->next->next)"


I've a struct linkedList like that

typedef struct linkedList l_List;

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

and my question is: what temp->next->next mean?
I've suspected that temp datatype is l_List* instead of l_List**
Why it's can use as level 2 pointer by that way?

cre:I found this code on another source

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

Solution

  • It is an equivalent to

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

    It should help you to understand what it means.

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

    is the same as

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