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