Files
university/S1/GdCP/uebung/a03.c
2025-04-28 16:59:44 +02:00

29 lines
594 B
C

typedef struct interval_s {
long low; // lower bound
long up; // upper bound
} interval_t;
long max(long a, long b) {
if (a > b) return a;
return b;
}
long min(long a, long b) {
if (a > b) return b;
return a;
}
int is_empty(const interval_t *a) {
return a->low > a-> up;
}
int is_empty_intersection(const struct interval_s *a, const struct interval_s *b) {
if (!a || !b) return 1;
const interval_t *l[] = {a, b};
for (int i = 0; i < 2; i++) {
if (is_empty(l[i])) return 1;
}
interval_t s = {max(a->low, b->low), min(a->up, b->up)};
return is_empty(&s);
};