Answers for "how to get the length of a linked list in c"

C
0

how to get the length of a linked list in c

typedef struct node{
    int value; //this is the value the node stores
    struct node *next; //this is the node the current node points to. this is how the nodes link
}node;

int len(node *head){
    node *tmp = head;
    int counter = 0;

    while(tmp != NULL){
        counter += 1;
        tmp = tmp->next;
    }
    return counter;
}
Posted by: Guest on October-18-2020

Code answers related to "how to get the length of a linked list in c"

Code answers related to "C"

Browse Popular Code Answers by Language