Which of the following two blocks of code is better overall?
One return statement, more indented code:
struct dnode *dllist_push_front(struct dllist *dllist, void *data)
{
struct dnode *dnode = malloc(sizeof(struct dnode));
if (dnode) {
dnode->data = data;
dnode->next = dllist->sentinel->next;
dnode->prev = dlllist->sentinel;
dnode->next->prev = dnode;
dllist->sentinel->next = dnode;
dllist->size++;
}
return dnode;
}
or,
Two return statments, less indented code:
struct dnode *dllist_push_front(struct dllist *dllist, void *data)
{
struct dnode *dnode = malloc (sizeof(struct dnode));
if (!dnode)
return NULL;
dnode->data = data;
dnode->next = dllist->sentinel->next;
dnode->prev = dlllist->sentinel;
dnode->next->prev = dnode;
dllist->sentinel->next = dnode;
dllist->size++;
return dnode;
}