Re: [PEPr] +1 for Structures::Structures_LinkedList
| From: | Anant Narayanan | Date: | Tue, 03 Oct 2006 21:06:09 +0000 |
| Subject: | Re: [PEPr] +1 for Structures::Structures_LinkedList | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-44282@lists.php.net to get a copy of this message | ||
Hi Dan,
> It's horribly expensive if you have to use previous() a lot, but
> because it is possible I think it would be best to keep the
> implementation and strongly recommend a doubly-linked list if you
> expect to use previous() more than a handful of times. So, on this
> basis I hope that you would reconsider making your vote conditional on
> previous() returning false in a singly-linked list.
It's not about whether you're able to do it or not. When you're
implementing a singly-linked list, you have to provide an honest
implementation of it, simply because everyone who has taken a course on
Data Structures will not expect to be able to use the previous() method.
Take the stack for example. It's a very simple data structure, with just
three methods. If you would start adding "convenience" methods to it,
which you can of course, it just becomes a queue, or even worse: an
array!
Correctness over Convenience :)
Cheers,
- Anant