+ 1
How to create a linked list using C programming?
Using C programming how to declare a linked list dynamically...
2 ответов
+ 4
What is a linked list? A collection of nodes, where each node stores a value and a pointer to the next node.
typedef struct node {
void * data;
struct node * next;
} node;
I chose void* here so you can use any datatype but you can replace that with int or char* or whatever.
Later in the program you just link them together.
node * a = make_node();
node * b = make_node();
a->next = b;
And now you have a linked list of size 2. Usually you'll want to b->next = NULL, so when looping through the list you have a way to tell when the list has ended. Then you can start at `a` and follow the ->next pointers until you hit NULL.