Removes the minimum from this heap. @return the removed entry's value
()
| 51 | * @return the removed entry's value |
| 52 | */ |
| 53 | public V removeMin() { |
| 54 | final V val = minValue(); |
| 55 | swap(0, --size); |
| 56 | int pos = 0; |
| 57 | while(pos < size / 2) { |
| 58 | int sm = 2 * pos + 1; |
| 59 | if(sm < size - 1 && compare(sm + 1, sm) < 0) sm++; |
| 60 | if(compare(pos, sm) <= 0) break; |
| 61 | swap(pos, sm); |
| 62 | pos = sm; |
| 63 | } |
| 64 | return val; |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * returns the value of the smallest key from this heap. |