I am trying to implement a singly linked list in C. A common implementation that you see floating around the internet is something like
typedef struct {
int head;
Node *tail;
} Node;
with methods like
Node cons(int head, Node tail) {
Node y;
y.head = head;
y.tail = malloc(sizeof(Node));
*y.tail = tail;
}
Performance is very important. Is there any way to implement a linked list in C that will be faster than this? For example, getting rid of the memory allocation (y.tail = malloc(sizeof(Node))
) should provide a significant speed increase.