()
| 42 | } |
| 43 | |
| 44 | public T remove() throws Exception { |
| 45 | if (list.isEmpty()) { |
| 46 | throw new Exception("Removing from an empty heap!"); |
| 47 | } |
| 48 | |
| 49 | T temp = list.get(0); |
| 50 | |
| 51 | T last = list.remove(list.size() - 1); |
| 52 | if (!list.isEmpty()) { |
| 53 | list.set(0, last); |
| 54 | downheap(0); |
| 55 | } |
| 56 | |
| 57 | return temp; |
| 58 | } |
| 59 | private void downheap(int index) { |
| 60 | int min = index; |
| 61 | int left = left(index); |