We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7a6d155 commit 41d09a3Copy full SHA for 41d09a3
src/main/java/com/rampatra/common/MinHeap.java
@@ -39,20 +39,20 @@ public MinHeap(int[] heap) {
39
* @param index
40
*/
41
public void minHeapify(int index) {
42
- int smallest = index;
+ int minIndex = index;
43
int leftIndex = 2 * index + 1;
44
int rightIndex = 2 * index + 2;
45
46
if (leftIndex < size && heap[index] > heap[leftIndex]) {
47
- smallest = leftIndex;
+ minIndex = leftIndex;
48
}
49
- if (rightIndex < size && heap[smallest] > heap[rightIndex]) {
50
- smallest = rightIndex;
+ if (rightIndex < size && heap[minIndex] > heap[rightIndex]) {
+ minIndex = rightIndex;
51
52
53
- if (smallest != index) {
54
- swap(index, smallest);
55
- minHeapify(smallest);
+ if (minIndex != index) {
+ swap(index, minIndex);
+ minHeapify(minIndex);
56
57
58
0 commit comments