Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Cleaned up some code and made it prettier
  • Loading branch information
Kim Lidström committed Feb 23, 2012
1 parent 68957ef commit 1eb85f1
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions list.c
Expand Up @@ -34,11 +34,10 @@ void list_destroy(list_node **list)
list_node* list_insert_after(list_node *node, void *data)
{
list_node *new_node = list_create(data);
if (new_node != NULL) {
if (new_node) {
new_node->next = node->next;
node->next = new_node;
}

return new_node;
}

Expand Down Expand Up @@ -108,30 +107,23 @@ void list_remove_by_data(list_node **list, void *data)
*/
list_node* list_find_node(list_node *list, list_node *node)
{
if (list == NULL || node == NULL) goto ret;

while (list) {
if (list == node) return list;
if (list == node) break;
list = list->next;
}
ret:
return NULL;
return list;
}

/* Finds an elemt in a list by the data pointer
* Arguments: A pointer to a list and a pointer to the data
*/
list_node* list_find_by_data(list_node *list, void *data)
{
if (list == NULL || data == NULL) goto ret;

while (list) {
if (list->data == data) return list;
if (list->data == data) break;
list = list->next;
}

ret:
return NULL;
return list;
}

/* Finds an element in the list by using the comparison function
Expand All @@ -140,12 +132,11 @@ list_node* list_find_by_data(list_node *list, void *data)
*/
list_node* list_find(list_node *list, int(*func)(list_node*,void*), void *data)
{
if (!func) goto ret;
if (!func) return NULL;
while(list) {
if (func(list, data) > 0) return list;
if (func(list, data) > 0) break;
list = list->next;
}
ret:
return NULL;
return list;
}

0 comments on commit 1eb85f1

Please sign in to comment.