File tree Expand file tree Collapse file tree 1 file changed +3
-2
lines changed
Expand file tree Collapse file tree 1 file changed +3
-2
lines changed Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ public Heap() {
1616 }
1717
1818 // Default as maxheap
19- // pass Comparator for min Heap
19+ // pass Comparator for min Heap
2020 // pass Comparator.reverseOrder() for min heap
2121 public Heap (Comparator <T > comparator ) {
2222 this .comparator = comparator ;
@@ -27,6 +27,7 @@ public Heap(Comparator<T> comparator) {
2727 public boolean add (T val ) {
2828 return offer (val );
2929 }
30+
3031 private Comparator <T > comparator = (o1 , o2 ) -> {
3132 return o1 .compareTo (o2 );
3233 };
@@ -59,7 +60,7 @@ public T poll() {
5960 list .set (1 , t );
6061 int i = 1 ;
6162 while (i < index ) {
62- int maxIndex = i , left = 28 , right = (2 * i ) + 1 ;
63+ int maxIndex = i , left = 2 * i , right = (2 * i ) + 1 ;
6364 if (left < index && comparator .compare (list .get (i ), list .get (left )) > 0 ) {
6465 maxIndex = left ;
6566 }
You can’t perform that action at this time.
0 commit comments