File tree 1 file changed +4
-3
lines changed
1 file changed +4
-3
lines changed Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ public void doMax(){
35
35
public boolean doExtractMax (){
36
36
if (this .heapSize > 0 ){
37
37
extractMax (this .arr );
38
- doBuildMaxHeap ( );
38
+ maxHeapify ( this . arr , 1 );
39
39
printArr ();
40
40
return true ;
41
41
}
@@ -91,9 +91,10 @@ private Node max(Node[] arr){
91
91
}
92
92
93
93
private Node extractMax (Node [] arr ){
94
+ Node root = arr [1 ];
94
95
swap (arr , heapSize , 1 );
95
96
this .heapSize --;
96
- return arr [ 1 ] ;
97
+ return root ;
97
98
}
98
99
99
100
private void insert (Node [] arr , Node x ){
@@ -104,7 +105,7 @@ private void insert(Node[] arr, Node x){
104
105
temp [temp .length - 1 ] = x ;
105
106
this .arr = temp ;
106
107
this .heapSize = temp .length - 1 ;
107
- if (this .arr [this .heapSize /2 ].priorityNumber > this .arr [this .heapSize ].priorityNumber ) return ;
108
+ if (this .heapSize != 1 && this . arr [this .heapSize /2 ].priorityNumber > this .arr [this .heapSize ].priorityNumber ) return ;
108
109
buildMaxHeap (this .arr );
109
110
}
110
111
You can’t perform that action at this time.
0 commit comments