Padding the array is a bit of a code smell. You can't just pad an array without allocating a new block of memory. After allocation you need to copy the array into the new space. This is a significant amount of overhead to a fairly straightforward and efficient algorithm.
Well, that's easy to fix - copy your array into a linked list so you an insert elements at the head efficiently. ;-)
Yes, the real problem with this implementation is the data structure they use. But is `next == null` a special case? ogod what do we do?!
Re:Special Cases Are a Code Smell
by banku_brougham on Saturday January 26, 2019 @07:35PM
(#19009560)
This is interesting. Is it possible to implement a linked list while eliminating the end of the list ‘edge case’, in the fashion of the parent article?
Re:Special Cases Are a Code Smell
by pure-awesome on Monday January 28, 2019 @06:55AM
(#19016774)
Create a "sentinel" node which represents null and also points to itself, perhaps?
The version with special cases feels cleaner to me.