| 13 | } |
| 14 | |
| 15 | private boolean bookHelper(CalendarNode cur, int targetStart, int targetEnd) { |
| 16 | if (targetStart > cur.end) { |
| 17 | // go to the right |
| 18 | if (cur.right == null) { |
| 19 | // we can insert event |
| 20 | cur.right = new CalendarNode(targetStart, targetEnd); |
| 21 | return true; |
| 22 | } |
| 23 | return bookHelper(cur.right, targetStart, targetEnd); |
| 24 | } else if (targetEnd < cur.start) { |
| 25 | // go to the left |
| 26 | if (cur.left == null) { |
| 27 | // we can insert event |
| 28 | cur.left = new CalendarNode(targetStart, targetEnd); |
| 29 | return true; |
| 30 | } |
| 31 | return bookHelper(cur.left, targetStart, targetEnd); |
| 32 | } |
| 33 | return false; |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | class CalendarNode { |