how to get size of a linked list python code example

Example 1: python size of linked list

def size():
  count = 0
  current_node = linked_list.head
  while(node != null):
    counter += 1
    current_node = current_node.next
  return count

Example 2: 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;
}

Tags:

C Example