fixed next and prev

This commit is contained in:
fragsornotfrags 2016-11-03 14:54:39 +01:00
parent 1e586acb37
commit d02fff67e9

12
asino.c
View file

@ -47,8 +47,8 @@ new_arg(void)
struct arg* struct arg*
push_arg(struct arg* a, struct arg *args) push_arg(struct arg* a, struct arg *args)
{ {
a->next = args; a->prev = args;
args->prev = a; args->next = a;
return a; return a;
} }
@ -80,8 +80,6 @@ load_arguments(struct arg *args, int idx, char **argv, int argc, struct arg **he
if(args == NULL){ if(args == NULL){
args = newA; args = newA;
*head = args; *head = args;
args->next = NULL;
args->prev = NULL;
args->idx = idx; args->idx = idx;
} else { } else {
args = push_arg(newA, args); args = push_arg(newA, args);
@ -113,7 +111,7 @@ struct arg *
get_element_node (struct arg *a, int idx) get_element_node (struct arg *a, int idx)
{ {
while (idx != a->idx) { while (idx != a->idx) {
a = a->prev; a = a->next;
} }
return a; return a;
} }
@ -165,7 +163,7 @@ print_elements(struct arg *elements, int nElements)
{ {
while (elements != NULL) { while (elements != NULL) {
printf ("%d. %s\n", elements->idx + 1, elements->str); printf ("%d. %s\n", elements->idx + 1, elements->str);
elements = elements->prev; elements = elements->next;
} }
} }
@ -175,7 +173,7 @@ free_elements (struct arg *ptr, int n)
struct arg *tmp; struct arg *tmp;
while (ptr != NULL) { while (ptr != NULL) {
tmp = ptr; tmp = ptr;
ptr = ptr->prev; // :^) ptr = ptr->next; // :^)
free (tmp->str); free (tmp->str);
free (tmp); free (tmp);
} }