This question already has an answer here:
- Structs with pointer to next struct 4 answers
I want to have a session where I insert totally 10 different integers in the size variable that is inside the linked list. I believe I should use result_register() for this?
When all 10 integers are stored I want to print them out by typing result->size.
I am new with linked lists so please be gentle.
struct result {
int size;
};
struct result* result_next()
{
// What do I type here?
}
void result_register(int size)
{
// What do I type here?
}
main
struct result* result;
while ((result = result_next()))
printf("%d\n", result->size);
Then I want to be able to print out the results by doing like above.
You're result should have a
next
pointer to point to the next node in the linked list:Then, assuming you've got a pointer the head you just walk the list;
To create a new item in the list you need something like this:
Now you can say:
This will give you a linked list with
3 -> 2 -> 1 -> 0