Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

That's arguably one of the only downsides of zero-based, and can be handled easily with negative indexing. Basically all indexing arithmetic is easier with zero-based.


Using an array as a heap is also easier with 1-based indexing:

  base-element := some-vector[i];
  left-child := some-vector[i * 2];
  right-child := some-vector[i * 2 + 1];
where the root element is `some-vector[1]'.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: