This repository has been archived on 2021-10-31. You can view files and clone it, but cannot push or open issues or pull requests.
sys_prog/midterm/lists/lists.c
2019-11-08 08:48:30 +01:00

42 lines
701 B
C

#include "lists.h"
struct list* concatenate_all(int count, struct list* lists[]) {
struct list* first = 0;
for (int i = 0; i < count; i++) {
struct list* l = lists[i];
if (l == 0) continue;
if (first == 0) {
first = l;
}
while (l->next != 0) {
l = l->next;
}
i++;
for (; lists[i] == 0 && i < count; i++);
if (i == count) {
break;
}
l->next = lists[i];
i--;
}
return first;
}
struct list* merge_sorted(struct list* a, struct list* b) {
if (a == 0) {
return b;
} else if (b == 0) {
return a;
} else {
if (a->value < b->value) {
a->next = merge_sorted(a->next, b);
return a;
} else {
b->next = merge_sorted(a, b->next);
return b;
}
}
}