From 23990f4a802d8f174ad01e21c27ae449988d807f Mon Sep 17 00:00:00 2001 From: Thomas Schmucker Date: Tue, 4 Aug 2020 17:37:53 +0200 Subject: format code --- dlist.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'dlist.c') diff --git a/dlist.c b/dlist.c index 5a11c5b..a2a5cfd 100644 --- a/dlist.c +++ b/dlist.c @@ -28,6 +28,12 @@ dlist_init(struct dlist *dlist) dlist->tail = NULL; } +bool +dlist_empty(struct dlist *dlist) +{ + return dlist->head == NULL; +} + static struct dlist_element * create_element(T data) { @@ -50,11 +56,11 @@ dlist_push_front(struct dlist *dlist, T data) if ( element != NULL ) { element->prev = NULL; /* Vorgänger ist in jedem Fall NULL */ - if ( dlist->head == NULL ) { /* empty list */ + if ( dlist_empty(dlist) ) { element->next = NULL; dlist->tail = element; } - else { /* non empty list */ + else { element->next = dlist->head; element->next->prev = element; } @@ -76,11 +82,11 @@ dlist_push_back(struct dlist *dlist, T data) if ( element != NULL ) { element->next = NULL; /* Nachfolger ist in jedem Fall NULL */ - if ( dlist->head == NULL ) { /* empty list */ + if ( dlist_empty(dlist) ) { element->prev = NULL; dlist->head = element; } - else { /* non empty list */ + else { element->prev = dlist->tail; element->prev->next = element; } @@ -238,8 +244,9 @@ dlist_free(struct dlist *dlist) void dlist_apply_rev(struct dlist *dlist, void (*visit)(T data, void *cl), void *cl) { - for ( struct dlist_element *elem = dlist->tail; elem; elem = elem->prev ) + for ( struct dlist_element *elem = dlist->tail; elem; elem = elem->prev ) { visit(elem->data, cl); + } } void @@ -272,8 +279,9 @@ remove_if(struct dlist *list) for ( elem = list->head; elem; elem = next ) { next = elem->next; - if ( (elem->data & 1) == 1 ) + if ( (elem->data & 1) == 1 ) { dlist_remove(list, elem); + } } } -- cgit v1.3