It doesn't seem like your maxHeapify method has a base case. Meaning, even when it finds the values you are looking for, it will keep looking for those values. You need a base case so that once the method finds what its looking for, it no longer continues calling itself. Try adding this:
if (largest != i){
int tmp = A[i];
A[i] = A[largest];
A[largest] = tmp;
}
else{ //putting return here prevents the method from calling itself again
return;
}
Last edited by BestJewSinceJC; Nov 29th, 2008 at 10:29 pm.
Reputation Points: 874
Solved Threads: 352
Posting Maven
Offline 2,758 posts
since Sep 2008