3 ms·
But on the other hand, last := vector[vector-length(vector)]; is nicer than last := vector[vector-length(vector) - 1]; so in the end I'd say 'de gustibu
by tmtvl 2y ago
But on the other hand,
last := vector[vector-length(vector)];
is nicer than
last := vector[vector-length(vector) - 1];
so in the end I'd say 'de gustibus non est disputandum' and people who prefer 0-based indexing can use most languages and I can dream of my own.
- naasking 2y agoThat'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.
- tmtvl 2y agoUsing 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]'.