Just to make it clear: you are being given a hard time because you are looking for a handout instead of solving the problem yourself. This is a very basic homework question tackled in "Introduction to Programming" 101 or 102. You
must solve it yourself.
Here are some hints:
1. Your linked list must have
links -- pointers to the next piece of the list.
1 2 3 4 5
|
struct node_t
{
int datum; // This is the thing stored in the list
node_t* next; // This is the link to the next node in the list.
};
|
2. Get out a piece of paper and a pencil, and draw yourself a linked list. It might look something like:
+----+ +----+ +----+
| 42 |-->| 19 |-->| -3 |-->NULL
+----+ +----+ +----+ |
The numbers are, of course, the data, and the arrows are the next node pointers.
Everything you do to this list you should first draw how you would do it yourself. Then make the computer do what you drew.
In the case of counting your list, you know that you must have a node pointer to the first item in the list. What can I do with that pointer to find the number of items in the list?
Those are some pretty big hints. Good luck!