()
| 30 | } |
| 31 | |
| 32 | public T remove() throws Exception{ |
| 33 | if(list.isEmpty()){ |
| 34 | throw new Exception("Removing from empty Heap"); |
| 35 | } |
| 36 | T temp = list.get(0); |
| 37 | |
| 38 | T last = list.remove(list.size() - 1); |
| 39 | |
| 40 | if(!list.isEmpty()){ |
| 41 | list.set(0, last); |
| 42 | |
| 43 | downheap(0); |
| 44 | } |
| 45 | return temp; |
| 46 | } |
| 47 | |
| 48 | private void downheap(int index) { |
| 49 |