Exemple #1
0
  // assume start < end
  // assume s <= start < end <= e
  // return true if one or more than one item in [start, end) has been inserted
  bool conflict(int start, int end) {
    if (inserted) return true; 
    if (start == s && end == e) {
      if (l == nullptr && r == nullptr) return inserted;
    }

    if (end <= p) {
      return l == nullptr ? false : l->conflict(start, end);
    }
    else if (start < p && end > p) {
      return (l == nullptr ? false : l->conflict(start, p)) ||
             (r == nullptr ? false : r->conflict(p, end));
    }
    else // (start >= p) {
      return r == nullptr ? false : r->conflict(start, end);
  }
Exemple #2
0
 bool book(int start, int end) {
   if (r.conflict(start, end))
     return false;
   r.insert(start, end);
   return true;
 }