Streamlined single linked lists some more.
This commit is contained in:
parent
aaa1b8bb5d
commit
56e195c9b4
|
@ -160,7 +160,7 @@ static inline void* read_node_i_single_linked_list(linked_list_t *list, size_t i
|
|||
|
||||
/* Check if dealing with the head. */
|
||||
if (!i)
|
||||
return list->head->data;
|
||||
return (list->head) ? list->head->data : NULL;
|
||||
|
||||
/* Loop and read. */
|
||||
node_t *current = list->head;
|
||||
|
@ -168,7 +168,7 @@ static inline void* read_node_i_single_linked_list(linked_list_t *list, size_t i
|
|||
current = current->next;
|
||||
|
||||
/* Got to the requested node, return the stored data. */
|
||||
return current->data;
|
||||
return (current) ? current->data : NULL;
|
||||
}
|
||||
|
||||
/* This function retrieves a pointer to the ith node, returns NULL on failure. */
|
||||
|
@ -340,7 +340,7 @@ static inline void remove_node_head_data_single_linked_list(linked_list_t *list,
|
|||
/* This function reads the data at the last node, will return NULL on invalid input or first node being NULL. */
|
||||
static inline void* read_node_tail_single_linked_list(linked_list_t *list) {
|
||||
/* Sanity check. */
|
||||
assert(list && (list->head));
|
||||
assert(list);
|
||||
|
||||
/* Delegate. */
|
||||
return read_node_i_single_linked_list(list, list->length - 1);
|
||||
|
@ -350,7 +350,7 @@ static inline void* read_node_tail_single_linked_list(linked_list_t *list) {
|
|||
/* Sets the error code in error (instead of returning it). */
|
||||
static inline node_t* get_node_tail_single_linked_list(linked_list_t *list) {
|
||||
/* Sanity check. */
|
||||
assert(list && (list->head));
|
||||
assert(list);
|
||||
|
||||
/* Delegate. */
|
||||
return get_node_i_single_linked_list(list, list->length - 1);
|
||||
|
|
Loading…
Reference in New Issue