mirror of
https://gitlab.gwdg.de/j.hahn02/university.git
synced 2026-01-01 14:54:25 -05:00
cleanup
This commit is contained in:
28
S1/GdCP/a03.c
Normal file
28
S1/GdCP/a03.c
Normal file
@@ -0,0 +1,28 @@
|
||||
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);
|
||||
};
|
||||
Reference in New Issue
Block a user