This commit is contained in:
@@ -22,19 +22,15 @@ int dlist_insert(struct dlist **l, size_t index, int e)
|
||||
{
|
||||
if(!l) return 1;
|
||||
|
||||
struct dlist *new_node = malloc(sizeof(struct dlist));
|
||||
if(!new_node) return 1;
|
||||
//struct dlist *new_node = malloc(sizeof(struct dlist));
|
||||
//if(!new_node) return 1;
|
||||
|
||||
//struct dlist *tmp = *l;
|
||||
|
||||
if(index == 0){
|
||||
|
||||
new_node->prev = NULL;
|
||||
new_node->next = *l;
|
||||
new_node->data = e;
|
||||
//new_node->next->prev = new_node;
|
||||
|
||||
//dlist_append(*l, e);
|
||||
*l = dlist_append(*l, e);
|
||||
if(!l) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -48,14 +44,15 @@ int dlist_insert(struct dlist **l, size_t index, int e)
|
||||
|
||||
if(!tmp) return 1;
|
||||
|
||||
//struct dlist *new_node = malloc(sizeof(struct dlist));
|
||||
//if(!new_node) return 1;
|
||||
struct dlist *new_node = malloc(sizeof(struct dlist));
|
||||
if(!new_node) return 1;
|
||||
|
||||
new_node->data = e;
|
||||
new_node->next = tmp;
|
||||
tmp->prev->next = new_node;
|
||||
new_node->prev = tmp->prev;
|
||||
tmp->prev = new_node;
|
||||
new_node->next = tmp->next;
|
||||
new_node->prev = tmp;
|
||||
|
||||
if (tmp->next != NULL) tmp->next->prev = new_node;
|
||||
tmp->next = new_node;
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -65,10 +62,10 @@ struct dlist *dlist_delete_at(struct dlist **l, size_t index)
|
||||
{
|
||||
if(!l || *l) return NULL;
|
||||
|
||||
struct dlist *old = *l;
|
||||
struct dlist *old = NULL;
|
||||
if(index == 0){
|
||||
|
||||
old->next->prev = NULL;
|
||||
old = *l;
|
||||
*l = old->next;
|
||||
|
||||
return old;
|
||||
@@ -82,6 +79,8 @@ struct dlist *dlist_delete_at(struct dlist **l, size_t index)
|
||||
ind ++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(ind == index -1){
|
||||
|
||||
old = tmp->next;
|
||||
|
||||
Reference in New Issue
Block a user