Nested* Nested_create(List list) {
Nested* new = malloc(sizeof(Nested));
new->list = list;
new->next = NULL;
return new;
}
void Nested_add(Nested** proot, Nested* node) {
if (*proot == NULL) {
*proot = node;
} else {
Nested* cur = *proot;
while (cur->next)
cur = cur->next;
cur->next = node;
}
}
void createlistoflists(Nested **LIST, List list1, List list2, List list3) {
Nested_add(LIST, Nested_create(list1));
Nested_add(LIST, Nested_create(list2));
Nested_add(LIST, Nested_create(list3));
}
In a single function:
void createlistoflists(Nested **LIST, List list1, List list2, List list3) {
List lists[] = {list1, list2, list3};
for (List* it = lists; it < lists + 3; ++it) {
Nested* node = malloc(sizeof(Nested));
node->list = *it;
node->next = NULL;
*LIST = node;
LIST = &(*LIST)->next;
}
}
11
solved Creating a list with elements other lists (same struct)