diff --git a/cv4/list_ops.c b/cv4/list_ops.c index b040c63..8c1098d 100644 --- a/cv4/list_ops.c +++ b/cv4/list_ops.c @@ -4,15 +4,21 @@ list_t *new_list(size_t length, list_element_t elements[]){ list_t* list = (list_t*)malloc(sizeof(list_t) + length * sizeof(list_element_t)); list->length = length; + //list->elements = list + sizeof(list_t); memcpy(list->elements,elements, length*sizeof(list_element_t)); return list; } // append entries to a list and return the new list list_t *append_list(list_t *list1, list_t *list2){ - if(list1==list2){}; - return NULL; +// list3.lenght=list1->lenght+list2->lenght; + list_t* list3 = (list_t*)malloc(sizeof(list_t) + (list1->length+list2->length) * sizeof(list_element_t)); + list3->length = list1->length+list2->length; + //list->elements = list + sizeof(list_t); + memcpy(list3->elements,list1->elements, list1->length*sizeof(list_element_t)); + memcpy(list3->elements+list1->length*sizeof(list_element_t),list2->elements, list2->length*sizeof(list_element_t)); + return list3; } // filter list returning only values that satisfy the filter function