(int i)
| 241 | } |
| 242 | |
| 243 | private void heapDown(int i) |
| 244 | { |
| 245 | int iL = leftChild(i); |
| 246 | int iR = rightChild(i); |
| 247 | //While we have two children, make sure we are smaller |
| 248 | while (childIsSmallerAndValid(i, iL) || childIsSmallerAndValid(i, iR)) |
| 249 | { |
| 250 | //we are larger then one of ours children, so swap with the smallest of the two |
| 251 | if ( iR < size && cmp(iL, iR) > 0 )//Right is the smallest |
| 252 | { |
| 253 | swapHeapValues(i, iR); |
| 254 | i = iR; |
| 255 | } |
| 256 | else//Left is smallest or lef tis only option |
| 257 | { |
| 258 | swapHeapValues(i, iL); |
| 259 | i = iL; |
| 260 | } |
| 261 | |
| 262 | iL = leftChild(i); |
| 263 | iR = rightChild(i); |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | /** |
| 268 | * Heapify up from the given index in the heap and make sure everything is |
no test coverage detected