submition3

This commit is contained in:
kr820js 2024-03-10 17:37:21 +01:00
parent 83f9a7726a
commit 2deb1d262e

View File

@ -4,15 +4,21 @@
list_t *new_list(size_t length, list_element_t elements[]){ 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_t* list = (list_t*)malloc(sizeof(list_t) + length * sizeof(list_element_t));
list->length = length; list->length = length;
//list->elements = list + sizeof(list_t);
memcpy(list->elements,elements, length*sizeof(list_element_t)); memcpy(list->elements,elements, length*sizeof(list_element_t));
return list; return list;
} }
// append entries to a list and return the new list // append entries to a list and return the new list
list_t *append_list(list_t *list1, list_t *list2){ list_t *append_list(list_t *list1, list_t *list2){
if(list1==list2){}; // list3.lenght=list1->lenght+list2->lenght;
return NULL; 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 // filter list returning only values that satisfy the filter function