I was studying linked list (single & double) in C. From many basic tutorials i've read, the average of the tutorials have two way to store linked list. Such as:
- Using *head
struct ListItem *head;
struct ListItem *a = (struct ListItem *) malloc(sizeof(struct ListItem));
a->data = 10;
a->next = NULL;
struct ListItem *b = (struct ListItem *) malloc(sizeof(struct ListItem));
b->data = 25;
b->next = NULL;
// Link it!
head = a;
a->next = b;
- Using other structure (
struct jsw_list
) as code example below:
struct jsw_list {
struct jsw_node *head;
struct jsw_node *tail;
size_t size;
};
struct jsw_list *new_list(int has_dummy_head, int has_dummy_tail)
{
struct jsw_list *rv = (struct jsw_list *) malloc(sizeof(struct jsw_list));
//.
//.
//.
}
struct jsw_list *list = new_list(1,1);
struct jsw_node *node;
node = insert_after(list, list->head, 10000);
node = insert_after(list, node, 5000);
Which better?
Please Enlightenment
Thank You