This commit is contained in:
@@ -53,9 +53,12 @@ int list_insert(struct list **l, size_t index, int e){
|
|||||||
|
|
||||||
if(index == 0){
|
if(index == 0){
|
||||||
|
|
||||||
|
*l = list_append(*l, e);
|
||||||
|
/*
|
||||||
new_node->data = e;
|
new_node->data = e;
|
||||||
new_node->next = *l;
|
new_node->next = *l;
|
||||||
*l = new_node;
|
*l = new_node;
|
||||||
|
*/
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,13 +20,19 @@ struct dlist *dlist_append(struct dlist *l, int e)
|
|||||||
|
|
||||||
int dlist_insert(struct dlist **l, size_t index, int e)
|
int dlist_insert(struct dlist **l, size_t index, int e)
|
||||||
{
|
{
|
||||||
struct dlist *tmp = *l;
|
if(!l) return 1;
|
||||||
|
|
||||||
|
struct dlist *new_node = malloc(sizeof(struct dlist));
|
||||||
|
if(!new_node) return 1;
|
||||||
|
|
||||||
|
//struct dlist *tmp = *l;
|
||||||
|
|
||||||
if(index == 0){
|
if(index == 0){
|
||||||
dlist_append(*l, e);
|
dlist_append(*l, e);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct dlist *tmp = *l;
|
||||||
size_t ind = 0;
|
size_t ind = 0;
|
||||||
while(tmp != NULL && ind < index - 1){
|
while(tmp != NULL && ind < index - 1){
|
||||||
|
|
||||||
@@ -36,8 +42,8 @@ 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;
|
||||||
|
|||||||
Reference in New Issue
Block a user