3 ms·
> For example, "How do you find the middle element of a singly linked list in one pass?" The answer, without comment, makes a presumption about how to define t
by thaumasiotes 8y ago
> For example, "How do you find the middle element of a singly linked list in one pass?" The answer, without comment, makes a presumption about how to define the "middle" of a list with even length. And it defines a linked list implementation with a magic, invisible head that requires extra code beyond the loop to compensate for.
I'm not sure what you mean by complaining about a magic, invisible head to the linked list. If you can't access the head of a linked list, you can't access any other part of it either.
However, as another comment points out elsewhere in the thread, there is a bigger problem -- the solution offered uses more than one pass.
- jfultz 8y agoI mean that the LinkedList class is defined so that "new LinkedList()" returns not a list of length zero, but a list of length 1 with the first element containing the string "head". The actual list it creates is {"head", "1", "2", "3", "4"}, despite the fact that the output claims the list has 4 elements.