2024-03-10 14:35:01 +00:00
|
|
|
#include "list_ops.h"
|
2024-03-10 15:43:14 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdbool.h>
|
2024-03-10 14:35:01 +00:00
|
|
|
|
2024-03-10 15:43:14 +00:00
|
|
|
list_t *new_list(size_t length, list_element_t elements[]) {
|
|
|
|
size_t size = sizeof(list_t) + length * sizeof(list_element_t);
|
2024-03-10 15:07:14 +00:00
|
|
|
|
2024-03-10 15:43:14 +00:00
|
|
|
list_t *newList = (list_t *)malloc(size);
|
2024-03-10 15:07:14 +00:00
|
|
|
|
2024-03-10 15:43:14 +00:00
|
|
|
if (newList == NULL) {
|
|
|
|
return NULL;
|
2024-03-10 15:07:14 +00:00
|
|
|
}
|
|
|
|
|
2024-03-10 15:43:14 +00:00
|
|
|
newList->length = length;
|
2024-03-10 14:35:01 +00:00
|
|
|
|
2024-03-10 15:43:14 +00:00
|
|
|
for (size_t i = 0; i < length; ++i) {
|
|
|
|
newList->elements[i] = elements[i];
|
2024-03-10 15:07:14 +00:00
|
|
|
}
|
|
|
|
|
2024-03-10 15:43:14 +00:00
|
|
|
return newList;
|
2024-03-10 15:07:14 +00:00
|
|
|
}
|