Skip to content

Commit

Permalink
Cleaned up some code and made it prettier
Browse files Browse the repository at this point in the history
  • 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
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@ void list_destroy(list_node **list)
list_node* list_insert_after(list_node *node, void *data) list_node* list_insert_after(list_node *node, void *data)
{ {
list_node *new_node = list_create(data); list_node *new_node = list_create(data);
if (new_node != NULL) { if (new_node) {
new_node->next = node->next; new_node->next = node->next;
node->next = new_node; node->next = new_node;
} }

return 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) list_node* list_find_node(list_node *list, list_node *node)
{ {
if (list == NULL || node == NULL) goto ret;

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


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

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

return list;
ret:
return NULL;
} }


/* Finds an element in the list by using the comparison function /* 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) list_node* list_find(list_node *list, int(*func)(list_node*,void*), void *data)
{ {
if (!func) goto ret; if (!func) return NULL;
while(list) { while(list) {
if (func(list, data) > 0) return list; if (func(list, data) > 0) break;
list = list->next; list = list->next;
} }
ret: return list;
return NULL;
} }


0 comments on commit 1eb85f1

Please sign in to comment.