Skip to main content
added 1 character in body
Source Link
JS1
  • 28.6k
  • 3
  • 41
  • 83

###Bug: can't delete head node###

Your delete_node() function doesn't work if the node you want to delete is the head of the list. In fact, the function signature can't work:

void deleteNode(node_t *node, node_t *head);

Since the head pointer can change if you delete it, your signature has to be one of these two instead;

void deleteNode(node_t *node, node_t **head);
node_t deleteNode*deleteNode(node_t *node, node_t *head);

###Insert should be renamed###

Since your "insert" function adds to the end of the list, I think it should be called append() instead.

###Bug: can't delete head node###

Your delete_node() function doesn't work if the node you want to delete is the head of the list. In fact, the function signature can't work:

void deleteNode(node_t *node, node_t *head);

Since the head pointer can change if you delete it, your signature has to be one of these two instead;

void deleteNode(node_t *node, node_t **head);
node_t deleteNode(node_t *node, node_t *head);

###Insert should be renamed###

Since your "insert" function adds to the end of the list, I think it should be called append() instead.

###Bug: can't delete head node###

Your delete_node() function doesn't work if the node you want to delete is the head of the list. In fact, the function signature can't work:

void deleteNode(node_t *node, node_t *head);

Since the head pointer can change if you delete it, your signature has to be one of these two instead;

void deleteNode(node_t *node, node_t **head);
node_t *deleteNode(node_t *node, node_t *head);

###Insert should be renamed###

Since your "insert" function adds to the end of the list, I think it should be called append() instead.

Source Link
JS1
  • 28.6k
  • 3
  • 41
  • 83

###Bug: can't delete head node###

Your delete_node() function doesn't work if the node you want to delete is the head of the list. In fact, the function signature can't work:

void deleteNode(node_t *node, node_t *head);

Since the head pointer can change if you delete it, your signature has to be one of these two instead;

void deleteNode(node_t *node, node_t **head);
node_t deleteNode(node_t *node, node_t *head);

###Insert should be renamed###

Since your "insert" function adds to the end of the list, I think it should be called append() instead.