K
Karl Malbrain
Tim Rentsch wrote:[discussing 1-origin arrays versus 0-origin arrays]
0-based heaps have carbunkles. End of.
Please excuse my temerity, but I think you are too good
a programmer for this to be true. Take a run at writing
a 0-based heap, not just dashing it off but really trying
to do a good clean job, and see if it comes out better
than you expect. I will if you will.I don't see what the problem is with 0 based heaps.
It's slightly awkward. In a 0 based heap the children of node n are
at nodes 2*n+1 and 2*n+2. The parent of node n is at (n-1)/2. In a 1
based heap the children of node n are at 2*n and 2*n+2; the parent of
node n is at n/2.
Not being able to write C code without 1 based arrays
is like not be able to ride a bicycle without training wheels.
True. Then again, civilized languages let you select the array base
to suit the problem.
But C does allow you to select the base. Just use BES (originally
from the IBM 700 series, Block ending with symbol), and use negative
indexing down from the high end.
Karl M