Can we improve C implementation of linked list?
letsaguiar opened this issue · comments
Letícia Aguiar commented
I have some ideas to improve the C implementation of linked list.
- Create a type
LinkedList
with a head and a tail. This will improve the performance of insert operation, since we'll don't need to traverse the list anymore.
typedef struct
{
Node *head;
Node *tail;
} LinkedList;
- In the insert method, there's no need to receive a pointer to pointer as the head node
void insert(int value, Node *head)
{
Node *node;
node->data = value;
node->next = NULL;
while (head->next)
head = head->next;
if (!head)
head = node;
else
head->next = node;
}
-
Linked Lists should support search, insert at and delete at operations.
-
We should create a destroy method to free all nodes of a list.
Debojit Ganguly commented
Yes go ahead