mirror of
https://gitlab.gwdg.de/j.hahn02/university.git
synced 2026-01-01 06:44:25 -05:00
29 lines
594 B
C
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);
|
|
};
|