开发者

What are some well coded examples of standard data structures in PHP? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. 开发者_如何学Go Closed 12 years ago.

I'd like to see some well done PHP code samples of some standard data structures.

Do you know of any code samples of Classes like Linear Linked Lists, Stacks, Queues, Binary Search Trees, etc?


PHP's Standard PHP Library (SPL) provides a set of standard data structures, including Linked Lists, Stacks, Queues and Heaps.

You can find some code samples of them at Lorenzo Alberton's site.


A lot of the Wikipedia pages on specific data structures include pseudocode implementations of them. If you know some PHP already, it shouldn't be too much of a challenge to translate that pseudocode into real PHP code. You'd learn about the data structures themselves, and about PHP, in the process.

Although the implementation of data structures is generally very similar across languages, each language has different conventions and idioms when it comes to designing the interface (the abstract data type) that represents a data structure.

Another place where languages differ is their treatment of pointers/references. (PHP doesn't explicitly support pointers, but — if I remember correctly — you can choose whether or not your objects get passed by reference.) It's important to understand how this works in your language, especially when implementing linked or tree-based data structures.

The memory management scheme (which is garbage collection in the case of PHP) also needs to be taken into consideration when implementing a data structure, as it can affect performance.


you can get good coding help on data structures in php from here: http://www.codediesel.com/php/ particularly: http://www.codediesel.com/php/linked-list-in-php/ http://www.codediesel.com/algorithms/doubly-linked-list-in-php/

Also other help: http://www.phpclasses.org/package/708-PHP-Linked-List.html http://www.phpclasses.org/browse/file/2369.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜