# Find Length of a Linked List (Iterative)

1,298.0K Views

Write a C function to count number of nodes in a given singly linked list.

For example, the function should return 6 for linked list 1->3->1->4->2->1.

SherlockHolmes Expert Asked on 4th August 2015 in

ITERATIVE SOLUTION-

``` /*
* File:   main.cpp
* Author: akash
*
* Created on 12 August, 2015, 4:57 PM
*/
#include <stdio.h>
#include <stdlib.h>
struct node
{
int data;
struct node* next;
};
{
struct node* add_node = (struct node*) malloc(sizeof(struct node));
}
return 0;
// count is 1 + count of remaining list
}
int main(){
return 0;
}
```

SherlockHolmes Expert Answered on 13th August 2015.

• ## More puzzles to try-

• ### How Many Sweets?

Sally and Anna bought 8 sweets and shared between themselves. Sally ate 2 more sweets than Anna did. How many ...Read More »
• ### Found underground riddle

These are a type of starchy food Mashed or fried they can be found They often come from Idaho And ...Read More »
• ### What am I?

If you look, you can’t see me. If you see me, you cannot see anything else. I can make you ...Read More »
• ### I’m very smart and can be dangerous riddle

I’m a 8 letter word let’s say 12345678. I’m very smart and can be dangerous, My 78 is the name ...Read More »

In Soldiers Parade, Captain Jacob gives the order to soldiers – Right Turn – About turn – Left turn Assuming ...Read More »
• ### Who was in the photograph?

A man is looking at a photograph of someone. His friend asks who it is. The man replies, “Brothers and ...Read More »
• ### Who is the doctor?

A boy and a doctor was fishing.The boy is the doctor’s son but the doctor is not the boy’s father. ...Read More »
• ### Four Letter Word riddle

Which four-letter word can be written forward, backward or upside down, and can still be read from left to right ...Read More »
• ### Key Hardest to Turn

Name a key which is hardest to turn.Read More »
• ### In which year was the grandfather born?

Recently, somebody told: “My grandfather was born on the first sunday of the year. His seventh birthday was also on ...Read More »
• ### What does this mean

What does this below simple rebus mean?Read More »
• ### Name 3 consecutive days puzzle

Can You Name Three Consecutive Days. Without Using The Words – Monday , Tuesday, Wednesday, Thursday, Friday, Saturday, Or Sunday?Read More »
• ### How long it will take?

It takes ten men ten hours to build a certain wall. How long does it take five men to build ...Read More »
• ### Five Brothers

My three brothers, my cousin and I are stood in a line. I am the shortest of all my brothers ...Read More »
• ### Teaching Year Riddle

Three teachers were discussing how long they had been teaching. Adrian and Betty had been teaching for a total of ...Read More »
• ### Count the Triangles

Can you count the triangle in below given figure ?Read More »
• ### Number Games

Fill in the boxes with numbers from 1-10. One number can be used only once.Read More »