Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 920
Peter Ajtai Avatar asked Aug 07 '10 03:08

Peter Ajtai


3 Answers

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.

like image 60
lkessler Avatar answered Oct 18 '22 16:10

lkessler


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

like image 32
Ankur Mukherjee Avatar answered Oct 18 '22 18:10

Ankur Mukherjee


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.

like image 37
David Avatar answered Oct 18 '22 18:10

David