offset 1 list indexing

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
 
T

Tim Rentsch

Phil Carmody said:
Tim Rentsch said:
Phil Carmody said:
[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.

Well thanks, but it wasn't the programmer in me speaking,
it was the craftsman.

My comment was meant to include both aspects.
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.

[snip]

I've been meaning to revisit my heap library for a while,
but I know that when I do the first thing I will do is
remove a little inefficiency, and even looking at 0-basing
it will be the last thing on my mind. Sorry.

I understand. Thank you for replying.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,199
Latest member
AnyaFlynn6

Latest Threads

Top