recursion - heapify function recursing endlessly -



recursion - heapify function recursing endlessly -

the next recursive heapify function array based priority queue/binary heap.

can tell me why i'm going infinite recursion?

private static void heapify(int i){ if(i < b_heap.size()/2){ int left = * 2; int right = left++; if(b_heap.get(i).getp() > b_heap.get(left).getp()){ swap(i,left); } if(b_heap.get(i).getp() > b_heap.get(right).getp()){ swap(i,right); } heapify(i++); heapify(i+2); } else{ return; } }

ok fixed infinite loop, function still doesn't heapify correctly.

here new code,

private static void heapify(int i){ decimalformat df = new decimalformat("0.00"); if(i < b_heap.size()/2){ int left = * 2; int right = * 2 +1; if(b_heap.get(i).getp() > b_heap.get(left).getp()){ swap(i,left); } if(b_heap.get(i).getp() > b_heap.get(right).getp()){ swap(i,right); } i++; heapify(i); } else{ return; } }

recursion heap priority-queue binary-heap

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -